[Issue 16212] New: Segfault using "with" for field access inside switch statement

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Mon Jun 27 13:30:19 PDT 2016


https://issues.dlang.org/show_bug.cgi?id=16212

          Issue ID: 16212
           Summary: Segfault using "with" for field access inside switch
                    statement
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: regression
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: kirsybuu at gmail.com

struct S {
   int field;
}
void main() {
   S s = S(3);
   switch (1) with (s) {
       case 1:
           field = 555; // segfault
           break;
       default:
           break;
    }
}

Linux 64-bit DMD 2.071.0 and 2.070.0:

$ dmd -g switchwithbug.d
$ gdb switchwithbug
(gdb) r
Program received signal SIGSEGV, Segmentation fault.
do_lookup_x (new_hash=new_hash at entry=129119144, 
    old_hash=old_hash at entry=0x7fffffffdcf0, 
    result=result at entry=0x7fffffffdd00, scope=0x7fff0000022b, i=i at entry=0, 
    flags=flags at entry=1, skip=skip at entry=0x0, 
    undef_map=undef_map at entry=0x7ffff7ffe1c8) at dl-lookup.c:83
83    dl-lookup.c: No such file or directory.
(gdb) bt
#0  do_lookup_x (new_hash=new_hash at entry=129119144, 
    old_hash=old_hash at entry=0x7fffffffdcf0, 
    result=result at entry=0x7fffffffdd00, scope=0x7fff0000022b, i=i at entry=0, 
    flags=flags at entry=1, skip=skip at entry=0x0, 
    undef_map=undef_map at entry=0x7ffff7ffe1c8) at dl-lookup.c:83
#1  0x00007ffff7de4961 in _dl_lookup_symbol_x (
    undef_name=0x40cd71 "pthread_mutex_destroy", undef_map=0x7ffff7ffe1c8, 
    ref=ref at entry=0x7fffffffddb8, symbol_scope=0x7ffff7ffe520, 
    version=0x7ffff7fd3b18, type_class=type_class at entry=1, flags=1, 
    skip_map=skip_map at entry=0x0) at dl-lookup.c:737
#2  0x00007ffff7de9527 in _dl_fixup (l=<optimized out>, 
    reloc_arg=<optimized out>) at ../elf/dl-runtime.c:111
#3  0x00007ffff7df04d5 in _dl_runtime_resolve ()
    at ../sysdeps/x86_64/dl-trampoline.S:45
#4  0x000000000043e1b5 in thread_term ()
#5  0x0000000000433503 in gc_term ()
#6  0x00000000004265a0 in rt_term ()
#7  0x0000000000423421 in rt.dmain2._d_run_main() ()
#8  0x00000000004233a1 in rt.dmain2._d_run_main() ()
#9  0x0000000000423312 in _d_run_main ()
#10 0x0000000000422b80 in main ()


DMD 2.069.2 and 2.069.0: No issue!


DMD 2.068.0, 2.067.1, 2.067.0, and even 2.065.0:
Program received signal SIGSEGV, Segmentation fault.
0x000000000041d3b3 in D main () at switchwithbug.d:8
8               field = 555;

Disassembly shows that "__withSym" hidden variable is not initialized:
   S s = S(3);
0x000000000041d3a8  <_Dmain+8>:  movl   $0x3,-0x10(%rbp)
   switch (1) with (s) {
       case 1:
           field = 555;
0x000000000041d3af  <_Dmain+15>:  mov    -0x8(%rbp),%rax
0x000000000041d3b3  <_Dmain+19>:  movl   $0x22b,(%rax)
           break;
0x000000000041d3b9  <_Dmain+25>:  xor    %eax,%eax
       default:
           break;
    }
}


This bug isn't limited to DMD either, making me think it is a front-end issue:

$ gdc --version
gdc (crosstool-NG 1.20.0 - 20150405-2.066.1-f378f9ab41) 4.9.2

Program received signal SIGSEGV, Segmentation fault.
strcmp () at ../sysdeps/x86_64/multiarch/../strcmp.S:132
132    ../sysdeps/x86_64/multiarch/../strcmp.S: No such file or directory.
(gdb) bt
#0  strcmp () at ../sysdeps/x86_64/multiarch/../strcmp.S:132
#1  0x00007ffff7de3e6c in check_match (sym=0x7ffff70dec08) at dl-lookup.c:177
#2  0x00007ffff7de47e6 in do_lookup_x (new_hash=new_hash at entry=245674643, 
    old_hash=old_hash at entry=0x7fffffffdb60, 
    result=result at entry=0x7fffffffdb70, scope=<optimized out>, 
    i=<optimized out>, i at entry=0, flags=flags at entry=1, skip=skip at entry=0x0, 
    undef_map=undef_map at entry=0x7ffff7ffe1c8) at dl-lookup.c:249
#3  0x00007ffff7de4961 in _dl_lookup_symbol_x (undef_name=0x4012d3 "munmap", 
    undef_map=0x7ffff7ffe1c8, ref=ref at entry=0x7fffffffdc28, 
    symbol_scope=0x7ffff7ffe520, version=0x7ffff7fd2030, 
    type_class=type_class at entry=1, flags=1, skip_map=skip_map at entry=0x0)
    at dl-lookup.c:737
#4  0x00007ffff7de9527 in _dl_fixup (l=<optimized out>, 
    reloc_arg=<optimized out>) at ../elf/dl-runtime.c:111
#5  0x00007ffff7df04d5 in _dl_runtime_resolve ()
    at ../sysdeps/x86_64/dl-trampoline.S:45
#6  0x000000000042daf9 in Dtor (this=...)
    at
/home/build/tmp/build/.build/src/gcc-4.9.2/libphobos/libdruntime/gc/gc.d:3149
#7  Dtor (this=...)
    at
/home/build/tmp/build/.build/src/gcc-4.9.2/libphobos/libdruntime/gc/gc.d:1433
#8  gc.gc.GC.Dtor() (this=...)
---Type <return> to continue, or q <return> to quit---
    at
/home/build/tmp/build/.build/src/gcc-4.9.2/libphobos/libdruntime/gc/gc.d:285
#9  0x0000000000418d96 in gc_term ()
    at
/home/build/tmp/build/.build/src/gcc-4.9.2/libphobos/libdruntime/gc/proxy.d:148
#10 0x0000000000407cb0 in rt_term ()
    at
/home/build/tmp/build/.build/src/gcc-4.9.2/libphobos/libdruntime/rt/dmain2.d:195
#11 0x0000000000407d29 in runAll (this=0x7fffffffdda0)
    at
/home/build/tmp/build/.build/src/gcc-4.9.2/libphobos/libdruntime/rt/dmain2.d:415
#12 0x00000000004079af in rt.dmain2._d_run_main() (
    this=this at entry=0x7fffffffdda0, dg=...)
    at
/home/build/tmp/build/.build/src/gcc-4.9.2/libphobos/libdruntime/rt/dmain2.d:386
#13 0x0000000000407b36 in _d_run_main (argc=1, argv=0x7fffffffdf08, 
    mainFunc=<optimized out>)
    at
/home/build/tmp/build/.build/src/gcc-4.9.2/libphobos/libdruntime/rt/dmain2.d:419
#14 0x0000000000402bf8 in main (argc=1, argv=0x7fffffffdf08)
    at
/home/kirsybuu/x86_64-gdcproject-linux-gnu/lib/gcc/x86_64-unknown-linux-gnu/4.9.2/include/d/__entrypoint.di:62

--


More information about the Digitalmars-d-bugs mailing list