Bug 23040 – importC: optimizer rejects null dereference of volatile pointer

Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2022-04-19T14:56:58Z
Last change time
2024-12-13T19:22:22Z
Keywords
ImportC, rejects-valid
Assigned to
No Owner
Creator
duser
Moved to GitHub: dmd#20091 →

Comments

Comment #0 by duser — 2022-04-19T14:56:58Z
void my_fatal() { *((volatile unsigned int *) 0) = (unsigned int) 0xdeadbeefUL; } compile: dmd -O -c test.c Error: null dereference in function my_fatal i see in https://github.com/dlang/dmd/blob/b1ac484/src/dmd/backend/cgelem.d#L6253 where the error is emitted, it has a check to allow this with volatile pointers but the keyword is ignored in importC
Comment #1 by bugzilla — 2022-04-20T06:56:43Z
volatile is ignored in ImportC because the D type system has no concept of volatile.
Comment #2 by bugzilla — 2023-04-09T05:50:53Z
You can work around it with something like: static void* p; *(unsigned int*)p = (unsigned int) 0xdeadbeefUL;
Comment #3 by robert.schadek — 2024-12-13T19:22:22Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/20091 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB