Bug 23055 – importC: using compound-literal array as pointer in CTFE gives 'dereference of invalid pointer'
Status
RESOLVED
Resolution
FIXED
Severity
minor
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2022-04-24T23:11:38Z
Last change time
2023-04-25T19:57:48Z
Keywords
CTFE, ImportC, pull
Assigned to
No Owner
Creator
duser
Comments
Comment #0 by duser — 2022-04-24T23:11:38Z
int fn()
{
int *p = (int[1]){0};
*p = 0;
return *p;
}
_Static_assert(fn() == 0, "");
int main()
{
return fn();
}
test.c(4): Error: dereference of invalid pointer `[0]`
test.c(7): called from here: `fn()`
test.c(7): while evaluating: `static assert(fn() == 0)`
it works outside CTFE
Comment #1 by bugzilla — 2022-05-12T06:40:29Z
While we might be able to make it work, it is invalid C11 code anyway.
Comment #2 by bugzilla — 2023-04-09T06:02:50Z
This now gives an assert error on ctfeexpr.d(578)
Comment #3 by dlang-bot — 2023-04-21T07:22:25Z
@WalterBright created dlang/dmd pull request #15121 "fix Issue 23055 - importC: using compound-literal array as pointer in CTFE gives 'dereference of invalid pointer'" fixing this issue:
- fix Issue 23055 - importC: using compound-literal array as pointer in CTFE gives 'dereference of invalid pointer'
- fix Issue 23055 - importC: using compound-literal array as pointer in CTFE gives 'dereference of invalid pointer'
https://github.com/dlang/dmd/pull/15121
Comment #4 by dlang-bot — 2023-04-25T19:57:48Z
dlang/dmd pull request #15121 "fix Issue 23055 - importC: using compound-literal array as pointer in CTFE gives 'dereference of invalid pointer'" was merged into master:
- 0cfd4558fef00c381e0e1a165211cb9506bc9339 by Walter Bright:
fix Issue 23055 - importC: using compound-literal array as pointer in CTFE gives 'dereference of invalid pointer'
- 5ec0ef3f8e641a829f217d10d47a0d081848ec6a by Walter Bright:
fix Issue 23055 - importC: using compound-literal array as pointer in CTFE gives 'dereference of invalid pointer'
https://github.com/dlang/dmd/pull/15121