[Issue 21821] New: Optimizer assumes immutables don't change, but they can in @system code
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Mon Apr 12 06:50:21 UTC 2021
https://issues.dlang.org/show_bug.cgi?id=21821
Issue ID: 21821
Summary: Optimizer assumes immutables don't change, but they
can in @system code
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: normal
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: bugzilla at digitalmars.com
Consider this code from core.lifetime:
void copyEmplacex(ref immutable(S) source, ref immutable(S) target) @system {
import core.stdc.string : memcpy;
memcpy(cast(S*) &target, cast(S*) &source, S.sizeof);
(cast() target).__xpostblit();
}
Note the last line casts away immutability, and the call to __xpostblit()
modifies the supposedly immutable `target`. The part of the optimizer that
fails this is the function Symbol_isAffected() in backend/symbol.d
The fix is to set a flag in `funcsym_p` when it is @safe, and enable the check
for immutability.
--
More information about the Digitalmars-d-bugs
mailing list