[Bug d/97889] d: OutOfMemoryError thrown when appending to an array with a side effect

ibuclaw at gdcproject dot org gcc-bugzilla@gcc.gnu.org
Wed Nov 18 11:41:55 GMT 2020


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97889

--- Comment #1 from Iain Buclaw <ibuclaw at gdcproject dot org> ---
Things go wrong because there is a SAVE_EXPR on the result of the library
function call of (val ~= 7).

It ends up being compiled down to:

  save = _d_arrayappendcTX (typeid(val), &val, 1),
    *(save.ptr + save.length - 1) = 7;

Then an address of this taken for the outer array append operation, so you end
up with:

  &(*(save = _d_arrayappendcTX (typeid(val), &val, 1),
      save.ptr + save.length - 1) = 7);

As _d_arrayappendcTX is known to return the new value of `val`, which is also
passed by reference, this can be instead lowered to ignore the return value,
and create a SAVE_EXPR on `&val' instead.

  save = &val,
    _d_arrayappendcTX (typeid(val), save, 1),
    (*save).ptr + (*save).length - 1 = 7,
    *save;


More information about the Gcc-bugs mailing list