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

--- Comment #12 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-12 branch has been updated by Iain Buclaw
<ibuc...@gcc.gnu.org>:

https://gcc.gnu.org/g:016047f54713dc601c661ab57c78a26da3759608

commit r12-9729-g016047f54713dc601c661ab57c78a26da3759608
Author: Iain Buclaw <ibuc...@gdcproject.org>
Date:   Mon Jun 26 02:29:46 2023 +0200

    d: Fix crash in d/dmd/root/aav.d:127 dmd_aaGetRvalue from
DsymbolTable::lookup

    Backports patch from upstream dmd mainline for fixing PR110113.

    The data being Mem.xrealloc'd contains many Array(T) fields, some of
    which have self references in their data.ptr field thanks to the
    smallarray optimization used by Array.

    Naturally then, the memcpy from old GC data to new retains those self
    referenced addresses, and the GC marks the old data as "free". Some time
    later GC.malloc will return a pointer to said "free" data. So now we
    have two GC references to the same memory. One that is treating the data
    as an Array(VarDeclaration) in dmd.escape.escapeByStorage, and the other
    as an AA in the symtab of a dmd.dsymbol.ScopeDsymbol.

    Fix this memory corruption by not storing the data in a global variable
    for reuse.  If there are no more live references, the GC will free it.

            PR d/110113

    gcc/d/ChangeLog:

            * dmd/escape.d (checkMutableArguments): Always allocate new buffer
for
            computing escapeBy.

    gcc/testsuite/ChangeLog:

            * gdc.test/compilable/test23978.d: New test.

    Reviewed-on: https://github.com/dlang/dmd/pull/15302
    (cherry picked from commit ae3a4cefd855512b10b833a56f275b701bacdb34)

Reply via email to