January 06, 2023
https://issues.dlang.org/show_bug.cgi?id=23603

          Issue ID: 23603
           Summary: ICE out of memory when using -lowmem
           Product: D
           Version: D2
          Hardware: x86
                OS: Windows
            Status: NEW
          Severity: critical
          Priority: P1
         Component: dmd
          Assignee: nobody@puremagic.com
          Reporter: Bastiaan@Veelo.net

The code below makes dmd throw an OutOfMemoryError when using the -lowmem option.

------------------------main.d-------------------
struct Array(T)
{
    T[] _payload;

    this(int b)
    {
        import std;
        _payload.length = b;
    }
}

struct A
{
    ushort[131070] a;
}

auto data = Array!A(255);
--------------------------------------------------

Invocation:
c:\d\dmd.2.101.2.windows\dmd2\windows\bin\dmd.exe -lowmem -c main.d

Memory usage climbs to ca. 3.5 GB with lots of available RAM to spare before giving up with:

---
ERROR: This is a compiler bug.
Please report it via https://issues.dlang.org/enter_bug.cgi
with, preferably, a reduced, reproducible example and the information below.
DustMite (https://github.com/CyberShadow/DustMite/wiki) can help with the
reduction.
---
DMD v2.101.2-dirty
predefs   DigitalMars LittleEndian D_Version2 all Windows Win32
CRuntime_Microsoft CppRuntime_Microsoft D_InlineAsm D_InlineAsm_X86 X86 assert
D_PreConditions D_PostConditions D_Invariants D_ModuleInfo D_Exceptions
D_TypeInfo D_HardFloat
binary    c:\d\dmd.2.101.2.windows\dmd2\windows\bin\dmd.exe
version   v2.101.2-dirty
config    c:\d\dmd.2.101.2.windows\dmd2\windows\bin\sc.ini
DFLAGS    -Ic:\d\dmd.2.101.2.windows\dmd2\windows\bin\..\..\src\phobos
-Ic:\d\dmd.2.101.2.windows\dmd2\windows\bin\..\..\src\druntime\import
---

core.exception.OutOfMemoryError@core\lifetime.d(126): Memory allocation failed
----------------

Without the -lowmem option an equal amount of memory is consumed before succeeding. We are however dependent on using -lowmem due to the size of the code base that this test was reduced from.

--