Bug 23490 – DMD creating corrupted vtable

Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2022-11-16T13:24:03Z
Last change time
2022-12-15T22:49:59Z
Keywords
pull
Assigned to
No Owner
Creator
Puneet Goel

Attachments

IDFilenameSummaryContent-TypeSize
1862code.tgzreduced code for reproducing bugapplication/x-compressed-tar567

Comments

Comment #0 by puneet — 2022-11-16T13:24:03Z
Created attachment 1862 reduced code for reproducing bug For certain module hierarchies, DMD is creating a corrupted vtable. Executable segfaults with the latest 2.101 release and LDC2 release 1.30. works fine with version 2.100 and with LDC2 1.29 releases. To replicate untar the attachment and: $ tar zxf code.tgz $ cd code $ rdmd test.d
Comment #1 by destructionator — 2022-11-16T14:20:39Z
Fascinating, deleting class Mu, which is a cousin to Frop, eliminates the segfault. And so does moving it below the definition of Frop! Definitely a regression introduced between .100 and .101 Traced to dmd commit b8cd91784e693b92eaf19034ab34c59a9836c98a to introduce the regression. Removing the code it added in expressionsem fixes the issue.
Comment #2 by destructionator — 2022-11-16T14:22:20Z
PR that has the offending commit: https://github.com/dlang/dmd/pull/14123
Comment #3 by ibuclaw — 2022-12-01T16:46:32Z
Confirmed. Function gets added to the vtable before the base vtbl has been copied across. Can add a internal ICE for this to ensure that the memcpy() doesn't override any existing entries. ``` --- a/compiler/src/dmd/dsymbolsem.d +++ b/compiler/src/dmd/dsymbolsem.d @@ -5153,6 +5153,7 @@ private extern(C++) final class DsymbolSemanticVisitor : Visitor } // Copy vtbl[] from base class + assert(cldec.vtbl.dim == 0); cldec.vtbl.setDim(cldec.baseClass.vtbl.dim); memcpy(cldec.vtbl.tdata(), cldec.baseClass.vtbl.tdata(), (void*).sizeof * cldec.vtbl.dim); ``` And running this test, we correctly hit the ICE. --- core.exception.AssertError@src/dmd/dsymbolsem.d(5156): Assertion failure ---------------- ??:? _d_assertp [0x557f420a04bc] src/dmd/dsymbolsem.d:5156 _ZN22DsymbolSemanticVisitor5visitEP16ClassDeclaration [0x557f41e16eff] src/dmd/dclass.d:1006 _ZN16ClassDeclaration6acceptEP7Visitor [0x557f41dc1565] src/dmd/dsymbolsem.d:130 _Z15dsymbolSemanticP7DsymbolP5Scope [0x557f41e07275] src/dmd/dmodule.d:1366 _ZN6Module19runDeferredSemanticEv [0x557f41de7ffc] src/dmd/dsymbolsem.d:2000 void dmd.dsymbolsem.DsymbolSemanticVisitor.visit(dmd.dmodule.Module).__lambda3!(dmd.dsymbol.Dsymbol).__lambda3(dmd.dsymbol.Dsymbol) [0x557f41e0d1e5] src/dmd/dsymbol.d:105 void dmd.dsymbol.foreachDsymbol(dmd.root.array.Array!(dmd.dsymbol.Dsymbol).Array*, void delegate(dmd.dsymbol.Dsymbol)) [0x557f41e008af] ---
Comment #4 by ibuclaw — 2022-12-01T17:07:32Z
With the ICE, it's easier to get a further reduction/consolidation of sources. frop.d --- import pop; class Mu: Pop { } class Frop : Pop { // final // does not fail if declared final void frolick() {} } --- pop.d --- import frop; import zoo: Zoo; class Pop { void poop(Frop ) { } void copy(Zoo ) { } } --- zoo.d --- import pop; import frop; class Foo(): Pop { override void poop(Frop frop) { frop.frolick; } } class Baz { Foo!() foo; Frop frop; } class Bar { static instance() { return new Baz; } auto ss = __traits(getAttributes, instance.frop); } class Zoo { } --- ICE triggered with: dmd -o- pop.d
Comment #5 by dlang-bot — 2022-12-01T18:12:33Z
@ibuclaw created dlang/dmd pull request #14661 "fix Issue 23490 - [REG 2.101] Class vtable being overwritten by class semantic ran out of order" fixing this issue: - fix Issue 23490 - [REG 2.101] Class vtable being overwritten by class semantic ran out of order https://github.com/dlang/dmd/pull/14661
Comment #6 by dlang-bot — 2022-12-03T09:18:13Z
dlang/dmd pull request #14661 "fix Issue 23490 - [REG 2.101] Class vtable being overwritten by class semantic ran out of order" was merged into stable: - 05ffb4e73629099faac07c50d5fa8f18bc2413a5 by Iain Buclaw: fix Issue 23490 - [REG 2.101] Class vtable being overwritten by class semantic ran out of order https://github.com/dlang/dmd/pull/14661
Comment #7 by dlang-bot — 2022-12-15T22:49:59Z
dlang/dmd pull request #14701 "merge stable" was merged into master: - 723ef3bc1d465c50d508cf75b2872c99a196f7df by Iain Buclaw: fix Issue 23490 - [REG 2.101] Class vtable being overwritten by class semantic ran out of order https://github.com/dlang/dmd/pull/14701