Bug 22484 – dmd generates wrong code for certain parameter/return sizes

Status
NEW
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2021-11-05T16:56:52Z
Last change time
2024-12-13T19:19:08Z
Keywords
wrong-code
Assigned to
No Owner
Creator
Stanislav Blinov
See also
https://issues.dlang.org/show_bug.cgi?id=22583
Moved to GitHub: dmd#18064 →

Comments

Comment #0 by stanislav.blinov — 2021-11-05T16:56:52Z
The assert in `bug` below triggers with and without -O. Test is definitely not minimal, but it's as far as I had the time to narrow it. --- // Comment out the align to make the bug disappear align(16) struct Param { uint x; } struct Result { // Set num elements to 4 to make the bug disappear int[8] a; } void* actual; // global just for assert // Comment out the `, int dummy=0` to make the bug disappear auto bug(void* arg, Param param, uint u, void delegate() a, void delegate() b, int dummy=0) { assert(arg == actual); return Result.init; } // Actual codebase was betterC, but this should compile with and without -betterC extern(C) int main(int argc, char** argv) { actual = argv[0]; actual.bug(Param.init, 0, {}, {}); return 0; }
Comment #1 by acehreli — 2021-11-05T17:31:28Z
For completeness, here is the error message: src/rt/dwarfeh.d:330: uncaught exception reached top of stack This might happen if you're missing a top level catch in your fiber or signal handler However, only the first of the three workarounds makes the bug disappear for me. Modifying or removing Result.a or removing 'dummy' did not remove the bug. Only removing align(16) removed the bug. There is no issue with -m32.
Comment #2 by stanislav.blinov — 2021-11-05T17:43:24Z
Yeah, sorry about that. I guess I should've stated more clearly that the actual manifestation of the issue is that wrong argument is being passed. I have no doubt that concrete behavior could vary. In my own codebase making the function extern(C) also works around the bug (can't test it trivially in this reduced case).
Comment #3 by stanislav.blinov — 2021-11-06T16:26:06Z
run.dlang.io shows the asserts fail on "all compilers" (which it starts from 2.060), though one would need to change main to this (otherwise it just shows empty 'Server error:'): void main(string[] args) { actual = &args[0]; actual.bug(Param.init, 0, {}, {}); }
Comment #4 by robert.schadek — 2024-12-13T19:19:08Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/18064 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB