Bug 23763 – ICE on operations involving zero-initialized structs
Status
RESOLVED
Resolution
FIXED
Severity
critical
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2023-03-08T00:27:32Z
Last change time
2023-03-16T01:20:57Z
Keywords
pull
Assigned to
No Owner
Creator
Mathias LANG
Comments
Comment #0 by pro.mathias.lang — 2023-03-08T00:27:32Z
```
struct BigInt { int[64] data; }
immutable BigInt a = BigInt.init;
void main ()
{
immutable BigInt b;
static assert(a == b);
}
```
This crashes the compiler:
```
Up to 2.063 : Failure with output:
-----
onlineapp.d(8): Error: variable b cannot be read at compile time
onlineapp.d(8): while evaluating: static assert(a == b)
-----
2.064 : Status -6 with output:
-----
onlineapp.d(8): Error: CTFE internal error: bad compare
dmd: ctfeexpr.c:1490: int ctfeRawCmp(Loc, Expression*, Expression*): Assertion `0' failed.
-----
2.065.0: Status -6 with output:
-----
onlineapp.d(8): Error: CTFE internal error: bad compare
dmd: ctfeexpr.c:1507: int ctfeRawCmp(Loc, Expression*, Expression*): Assertion `0' failed.
-----
2.066.1: Status -6 with output:
-----
onlineapp.d(8): Error: CTFE internal error: bad compare
dmd: ctfeexpr.c:1424: int ctfeRawCmp(Loc, Expression*, Expression*): Assertion `0' failed.
-----
2.067.1: Status -6 with output:
-----
onlineapp.d(8): Error: CTFE internal error: bad compare
dmd: ctfeexpr.c:1582: int ctfeRawCmp(Loc, Expression*, Expression*): Assertion `0' failed.
-----
2.068.2: Status -6 with output:
-----
onlineapp.d(8): Error: CTFE internal error: bad compare
dmd: ctfeexpr.c:1601: int ctfeRawCmp(Loc, Expression*, Expression*): Assertion `0' failed.
-----
2.069.2 to 2.073.2: Segfault with output: onlineapp.d(8): Error: CTFE internal error: bad compare
2.074.1 to 2.078.3: Segfault with output: onlineapp.d(8): Error: CTFE internal error: bad compare of `BigInt([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])` and `0`
Since 2.079.1: Status -4 with output: onlineapp.d(8): Error: CTFE internal error: bad compare of `BigInt([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])` and `0`
```
Comment #1 by dlang-bot — 2023-03-08T00:29:37Z
@Geod24 created dlang/dmd pull request #14966 "Fix 23763: Correctly handle struct constants with 0 initializer" fixing this issue:
- Fix 23763: Correctly handle struct constants with 0 initializer
At the moment, in dsymbolsem.d:1026, there is the following comment:
```
/* If a struct is all zeros, as a special case
* set its initializer to the integer 0.
* In AssignExp::toElem(), we check for this and issue
* a memset() to initialize the struct.
* Must do same check in interpreter.
*/
```
Turns out, the 'Must do same check in interpreter.' part was missing.
https://github.com/dlang/dmd/pull/14966
Comment #2 by dlang-bot — 2023-03-08T12:48:57Z
dlang/dmd pull request #14966 "Fix 23763: Correctly handle struct constants with 0 initializer" was merged into stable:
- 21baff377725b8cdd702abf0ea148fa095a0a014 by Geod24:
Fix 23763: Correctly handle struct constants with 0 initializer
At the moment, in dsymbolsem.d:1026, there is the following comment:
```
/* If a struct is all zeros, as a special case
* set its initializer to the integer 0.
* In AssignExp::toElem(), we check for this and issue
* a memset() to initialize the struct.
* Must do same check in interpreter.
*/
```
Turns out, the 'Must do same check in interpreter.' part was missing.
https://github.com/dlang/dmd/pull/14966
Comment #3 by dlang-bot — 2023-03-16T01:20:57Z
dlang/dmd pull request #14992 "merge stable" was merged into master:
- 5f15d561410277a0bff1a178f44486e055b3646e by Geod24:
Fix 23763: Correctly handle struct constants with 0 initializer
At the moment, in dsymbolsem.d:1026, there is the following comment:
```
/* If a struct is all zeros, as a special case
* set its initializer to the integer 0.
* In AssignExp::toElem(), we check for this and issue
* a memset() to initialize the struct.
* Must do same check in interpreter.
*/
```
Turns out, the 'Must do same check in interpreter.' part was missing.
https://github.com/dlang/dmd/pull/14992