Thread overview
Compiler Crash - Can anybody confirm with latest DMD?
19 hours ago
An Pham
10 hours ago
Vindex9
9 hours ago
Vindex9
5 hours ago
Dejan Lekic
19 hours ago

// Won't crash if using AliasSeq!(float)

void main()
{
    import std.stdio : writeln;
    import std.meta : AliasSeq;

    static foreach (T; AliasSeq!(float, double, real))
    {
        writeln("T=", T.stringof);

        // Static array
        {
            T v = T.sizeof;
            T[1] tsa;
            tsa[0] = v;
            writeln("v=", v, ", tsa=", tsa, ", sizeof=", tsa.sizeof);
        }
    }
}
10 hours ago

On Monday, 28 April 2025 at 22:51:17 UTC, An Pham wrote:

>

...

Very interesting. I don't crash the compiler itself (dmd 2.111.0, ArchLinux), but the program crashes at runtime.

Output:

T=float
v=4, tsa=[4], sizeof=4
T=double
v=8, tsa=[8], sizeof=8
T=real
(...series of unreadable characters...)
std.exception.ErrnoException@/usr/include/dlang/dmd/std/stdio.d(3124): Enforcement failed (Bad address)
----------------
??:? @safe noreturn std.exception.bailOut!(std.exception.ErrnoException).bailOut(immutable(char)[], ulong, scope const(char)[]) [0x5f49e374c7fa]
??:? @safe int std.exception.enforce!(std.exception.ErrnoException).enforce!(int).enforce(int, lazy const(char)[], immutable(char)[], ulong) [0x5f49e374c780]
??:? @safe void std.stdio.File.LockingTextWriter.put!(immutable(char)[]).put(scope immutable(char)[]) [0x5f49e374c697]
??:? @safe void std.range.primitives.doPut!(std.stdio.File.LockingTextWriter, immutable(char)[]).doPut(ref std.stdio.File.LockingTextWriter, ref immutable(char)[]) [0x5f49e374bdcb]
??:? @safe void std.range.primitives.put!(std.stdio.File.LockingTextWriter, immutable(char)[]).put(ref std.stdio.File.LockingTextWriter, immutable(char)[]) [0x5f49e374bdab]
??:? @safe void std.stdio.File.write!(immutable(char)[], real, immutable(char)[], real[1], immutable(char)[], ulong, char).write(immutable(char)[], real, immutable(char)[], real[1], immutable(char)[], ulong, char) [0x5f49e3775906]
??:? @safe void std.stdio.writeln!(immutable(char)[], real, immutable(char)[], real[1], immutable(char)[], ulong).writeln(immutable(char)[], real, immutable(char)[], real[1], immutable(char)[], ulong) [0x5f49e377585f]
??:? _Dmain [0x5f49e374bae3]

Everything works fine with the ldc2 and gdc compilers (I haven't checked the newest versions).

Output:

T=float
v=4, tsa=[4], sizeof=4
T=double
v=8, tsa=[8], sizeof=8
T=real
v=16, tsa=[16], sizeof=16

In any case, write a bug report.

9 hours ago

Static arrays of size 1 of the 'real' type do not work. A segmentation error occurs. I suspect that the bug is contained in std.stdio.write.

void main() {
    import std.stdio : writeln;
    real[1] tsa;
    writeln("tsa=", tsa, ", sizeof=", tsa.sizeof);
}
5 hours ago

Yep, it is reproducible. GDC and LDC2 produce good executables, while DMD produces an executable that crashes.