Bug 23450 – Unexpected constructor behaviour in DMD in rare cases

Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2022-11-01T16:07:43Z
Last change time
2024-12-13T19:25:21Z
Keywords
backend, wrong-code
Assigned to
No Owner
Creator
Keivan
See also
https://issues.dlang.org/show_bug.cgi?id=22583, https://issues.dlang.org/show_bug.cgi?id=21301
Moved to GitHub: dmd#20174 →

Comments

Comment #0 by keivan.shah — 2022-11-01T16:07:43Z
Today I came across a strange bug while using D with dmd. I have still not been able to figure out under what conditions does it happen but it seems to be a DMD related bug to me. Here is a reproducible snippet of the code ``` import std; alias DG = void delegate(); class TType { } class MyClass { this(TType t1, TType, double, double[2], double, double, DG, TType, TType, DG, DG, DG, double, double, double, double, double, ulong, bool) { assert(t1 is null); // I am passing null so should be null! // NOTE: Seems to work in LDC but fails in DMD. writeln("No Bug!"); } } void main() { auto tt = new TType; new MyClass(null, tt, 0, [0, 0], 0, 0, null, null, null, null, null, null, 0, 0, 0, 0, 0, 0, false); } ``` The code gives an assertion failure on the current versions of dmd (reproducible on run.dlang.io as well) and does not happen when using LDC. The bug seems to be sensitive to the number of arguments and their types making it reproducible only in very limited cases. I have tried my best to reduce it to minimum but still does require these many arguments. The end results seems to me like variables are shifted i.e. variable 1 gets value of variable 2 and so on, but don't have enough proof to support this.
Comment #1 by schveiguy — 2022-11-02T10:39:31Z
If you add a name for the second parameter in the function, you can see that the second parameter is null, and the first parameter is assigned `tt`. Even -vcg-ast thinks that it's passing them in the right order. I think this is a codegen bug.
Comment #2 by dkorpel — 2022-11-02T11:04:39Z
Might be the same as issue 21301. There's something about long parameter lists with arrays/small structs of floats/doubles where DMD messes up the register/stack assignment.
Comment #3 by keivan.shah — 2022-11-02T11:13:00Z
Also based on the discussion on the forums(https://forum.dlang.org/post/[email protected]), the issue might also be same as issue 22583
Comment #4 by robert.schadek — 2024-12-13T19:25:21Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/20174 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB