Bug 22126 – -checkaction=context should not print overlapped struct members
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2021-07-16T19:22:00Z
Last change time
2021-07-24T00:38:10Z
Keywords
pull
Assigned to
moonlightsentinel
Creator
Dennis
Comments
Comment #0 by dkorpel — 2021-07-16T19:22:00Z
Reduced test case:
```
struct S
{
union
{
double num;
immutable(char)[] name;
}
}
void main()
{
assert(S.init != S.init);
}
```
Compiling with -checkaction=context gives:
core.exception.OutOfMemoryError@src/core/exception.d(647): Memory allocation failed
----------------
The problem is that the double 'num' overlaps the length field of 'name', and double.nan interpreted as a length is 0x7FF8000000000000, so it's no wonder Memory allocation failed.
formatMembers in core/internal/dassert.d should not naively iterate over .tupleof but watch for overlapped fields.
Comment #1 by dlang-bot — 2021-07-23T21:45:53Z
@MoonlightSentinel created dlang/druntime pull request #3522 "Fix 22126 - Don't print overlapped fields with -checkaction=context" fixing this issue:
- Fix 22126 - Don't print overlapped fields with -checkaction=context
Detect overlapped fields by checking the offsets of adjacent members.
Those are replaced by a placeholder because we cannot determine wich
of the overlapped fields is valid (if any).
https://github.com/dlang/druntime/pull/3522
Comment #2 by dlang-bot — 2021-07-24T00:38:10Z
dlang/druntime pull request #3522 "Fix 22126 - Don't print overlapped fields with -checkaction=context" was merged into master:
- 9b3989c827984e8f4f9acd253071d80ce24fe5e2 by MoonlightSentinel:
Fix 22126 - Don't print overlapped fields with -checkaction=context
Detect overlapped fields by checking the offsets of adjacent members.
Those are replaced by a placeholder because we cannot determine wich
of the overlapped fields is valid (if any).
https://github.com/dlang/druntime/pull/3522