[Issue 23490] DMD creating corrupted vtable

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Dec 1 16:46:32 UTC 2022


https://issues.dlang.org/show_bug.cgi?id=23490

Iain Buclaw <ibuclaw at gdcproject.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ibuclaw at gdcproject.org

--- Comment #3 from Iain Buclaw <ibuclaw at gdcproject.org> ---
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 at 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]
---

--


More information about the Digitalmars-d-bugs mailing list