www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 21821] New: Optimizer assumes immutables don't change, but


          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 puremagic.com
          Reporter: bugzilla 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.

Apr 11 2021