Bug 19655 – DMD generates wrong code for some circular dependencies

Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2019-02-06T13:39:50Z
Last change time
2020-03-13T18:15:33Z
Keywords
pull
Assigned to
No Owner
Creator
Puneet Goel

Attachments

IDFilenameSummaryContent-TypeSize
1729ldcbug.tgzTar gzipped test caseapplication/x-compressed-tar13460

Comments

Comment #0 by puneet — 2019-02-06T13:39:50Z
Created attachment 1729 Tar gzipped test case Code attached. To reproduce the bug, untar and "make run" on a linux box. Note that wrong code is generated only when files/modules are compiled separately and then linked into an executable. That is how the included makefile compiles. More on this thread on Dlang Forum --> https://forum.dlang.org/thread/[email protected] When the exeuctable is run, I get: [email protected](6): func1 was never called ---------------- ??:? [0x4148b0] ??:? [0x4190ca] ??:? [0x4063ed] ??:? [0x402aa9] ??:? [0x4023c3] ??:? [0x402367] ??:? [0x40229f] ??:? [0x40608f] ??:? [0x405f87] ??:? [0x402324] ??:? __libc_start_main [0x7f96e3d2d82f] ??:? [0x402188] makefile:12: recipe for target 'run' failed make: *** [run] Error 1
Comment #1 by puneet — 2019-02-12T10:37:59Z
Marking as regression. Works with version 2.074.1; fails for 2.075 and later.
Comment #2 by dlang-bot — 2019-03-20T12:57:58Z
@puneet created dlang/dmd pull request #9471 "Fix issues 19655, 19656, 19657, 19746 & 19750" fixing this issue: - Fix issues 19655, 19656, 19657, 19746 & 19750 The Semantic (pass 1) analysis for classes is handled by visit(ClassDeclaration ) method of DsymbolSemanticVisitor class. For a given class, this method may be run multiple times in order to resolve forward references. The method incrementally tries to resolve the types referred to by the members of the class. The subsequent calls to this method are short-circuited if the class members have been fully analyzed. For this the code tests that it is not the first/main call to the method (semanticRun == PASS.init else branch), scx is not set, and that the cldec.symtab is already set. If all these conditions are met, the method returns. But before returning, the method was setting cldec.semanticRun to PASS.semanticdone. It should not set semanticRun since the class has not been fully analyzed yet. The base class analysis for this class could be pending and as a result vtable may not have been fully created. This fake setting of semanticRun results in the semantic analyzer to believe that the class has been fully analyzed. As exposed by the issues 19656, 19657, 19746 and 19750, it may result in compile time errors when a derived type class is getting analyzed and because of this fake semanticdone on the base class, the semantic analysis construes that an overridden method is not defined in the base class. Issue 19655 exposes a scenario where a buggy vtable may be created and a call to class method may result in execution of some adhoc code. https://github.com/dlang/dmd/pull/9471
Comment #3 by dlang-bot — 2019-03-21T12:11:52Z
dlang/dmd pull request #9471 "Fix issues 19655, 19656, 19657, 19746 & 19750" was merged into stable: - 592d0c790b90be5aab9d011200b98efa539b4a27 by Puneet Goel: Fix issues 19655, 19656, 19657, 19746 & 19750 The Semantic (pass 1) analysis for classes is handled by visit(ClassDeclaration ) method of DsymbolSemanticVisitor class. For a given class, this method may be run multiple times in order to resolve forward references. The method incrementally tries to resolve the types referred to by the members of the class. The subsequent calls to this method are short-circuited if the class members have been fully analyzed. For this the code tests that it is not the first/main call to the method (semanticRun == PASS.init else branch), scx is not set, and that the cldec.symtab is already set. If all these conditions are met, the method returns. But before returning, the method was setting cldec.semanticRun to PASS.semanticdone. It should not set semanticRun since the class has not been fully analyzed yet. The base class analysis for this class could be pending and as a result vtable may not have been fully created. This fake setting of semanticRun results in the semantic analyzer to believe that the class has been fully analyzed. As exposed by the issues 19656, 19657, 19746 and 19750, it may result in compile time errors when a derived type class is getting analyzed and because of this fake semanticdone on the base class, the semantic analysis construes that an overridden method is not defined in the base class. Issue 19655 exposes a scenario where a buggy vtable may be created and a call to class method may result in execution of some adhoc code. https://github.com/dlang/dmd/pull/9471
Comment #4 by dlang-bot — 2019-03-25T20:54:29Z
dlang/dmd pull request #9489 "Merge remote-tracking branch 'upstream/stable' into merge_stable" was merged into master: - 58878aeb8d32474ac24a0dd51446533a93602564 by Puneet Goel: Fix issues 19655, 19656, 19657, 19746 & 19750 (#9471) Fix issues 19655, 19656, 19657, 19746 & 19750 merged-on-behalf-of: Nicholas Wilson <[email protected]> https://github.com/dlang/dmd/pull/9489
Comment #5 by dlang-bot — 2020-03-13T18:15:33Z
dlang/dmd pull request #10913 "[dmd-cxx] Fix issues 19655, 19656, 19657, 19746 & 19750 (#9471)" was merged into dmd-cxx: - 968386f6da15cb30c229bf0ca3325d86c6fa8714 by Puneet Goel: Fix issues 19655, 19656, 19657, 19746 & 19750 (#9471) Fix issues 19655, 19656, 19657, 19746 & 19750 merged-on-behalf-of: Nicholas Wilson <[email protected]> https://github.com/dlang/dmd/pull/10913