www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Compiler Crash - Can anybody confirm with latest DMD?

reply An Pham <home home.com> writes:
// 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);
             }
         }
     }
Apr 28
next sibling parent reply Vindex9 <tech.vindex gmail.com> writes:
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.
Apr 29
parent Vindex9 <tech.vindex gmail.com> writes:
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`.

```d
void main() {
     import std.stdio : writeln;
     real[1] tsa;
     writeln("tsa=", tsa, ", sizeof=", tsa.sizeof);
}
```
Apr 29
prev sibling parent Dejan Lekic <dejan.lekic gmail.com> writes:
Yep, it is reproducible. GDC and LDC2 produce good executables, 
while DMD produces an executable that crashes.
Apr 29