[Issue 21664] New: Unsafe global initializer causes undefined behavior in @safe code
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Fri Feb 26 02:08:34 UTC 2021
https://issues.dlang.org/show_bug.cgi?id=21664
Issue ID: 21664
Summary: Unsafe global initializer causes undefined behavior in
@safe code
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: normal
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: snarwin+bugzilla at gmail.com
As of DMD 2.095.0, the following program compiles and exhibits undefined
behavior at runtime:
---
int* p = cast(int*) 0xDEADBEEF;
void main() @safe
{
int n = *p;
}
---
To prevent this, the compiler must forbid access to global variables in @safe
code unless it can prove that they have safe values. [1]
[1] https://dlang.org/spec/function.html#safe-values
--
More information about the Digitalmars-d-bugs
mailing list