ldc-developers / ldc

The LLVM-based D Compiler.
http://wiki.dlang.org/LDC
Other
1.21k stars 261 forks source link

ice-on-invalid with 2-line input. #2151

Open Ace17 opened 7 years ago

Ace17 commented 7 years ago

The following code crashes ldc2:

int main();
void f() {   main(); }
$ ldc2 crash.d -c
#0 0x00007ffff56b4115 llvm::sys::PrintStackTrace(llvm::raw_ostream&) (/usr/lib/x86_64-linux-gnu/libLLVM-3.9.so.1+0x707115)
#1 0x00007ffff56b22ce llvm::sys::RunSignalHandlers() (/usr/lib/x86_64-linux-gnu/libLLVM-3.9.so.1+0x7052ce)
#2 0x00007ffff56b23f2 (/usr/lib/x86_64-linux-gnu/libLLVM-3.9.so.1+0x7053f2)
#3 0x00007ffff476b0c0 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x110c0)
#4 0x0000555555849cff (/usr/bin/ldc2+0x2f5cff)
#5 0x0000555555855180 (/usr/bin/ldc2+0x301180)
#6 0x000055555585540f (/usr/bin/ldc2+0x30140f)
#7 0x0000555555854bf3 (/usr/bin/ldc2+0x300bf3)
#8 0x000055555583bc50 (/usr/bin/ldc2+0x2e7c50)
#9 0x000055555583d544 (/usr/bin/ldc2+0x2e9544)
#10 0x000055555583d734 (/usr/bin/ldc2+0x2e9734)
#11 0x0000555555806a18 (/usr/bin/ldc2+0x2b2a18)
#12 0x00005555558972fe (/usr/bin/ldc2+0x3432fe)
#13 0x000055555581a985 (/usr/bin/ldc2+0x2c6985)
#14 0x00005555558a7cc9 (/usr/bin/ldc2+0x353cc9)
#15 0x0000555555880f6f (/usr/bin/ldc2+0x32cf6f)
#16 0x000055555571028d (/usr/bin/ldc2+0x1bc28d)
#17 0x0000555555883081 (/usr/bin/ldc2+0x32f081)
#18 0x00007ffff3c4ee3f _D2rt6dmain211_d_run_mainUiPPaPUAAaZiZ6runAllMFZ9__lambda1MFZv (/usr/lib/x86_64-linux-gnu/libdruntime-ldc.so.71+0xa7e3f)
#19 0x00007ffff3c4ed84 _D2rt6dmain211_d_run_mainUiPPaPUAAaZiZ7tryExecMFMDFZvZv (/usr/lib/x86_64-linux-gnu/libdruntime-ldc.so.71+0xa7d84)
#20 0x00007ffff3c4ecad _d_run_main (/usr/lib/x86_64-linux-gnu/libdruntime-ldc.so.71+0xa7cad)
#21 0x00007ffff2f8c2b1 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x202b1)
#22 0x000055555566d39a _init (/usr/bin/ldc2+0x11939a)
[1]    6306 segmentation fault  ldc2 crash.d -c
$ ldc2 --version
LDC - the LLVM D compiler (1.1.1):
  based on DMD v2.071.2 and LLVM 3.9.1
  built with LDC - the LLVM D compiler (1.1.0)
  Default target: x86_64-pc-linux-gnu
  Host CPU: sandybridge
  http://dlang.org - http://wiki.dlang.org/LDC

  Registered Targets:
    aarch64    - AArch64 (little endian)
    aarch64_be - AArch64 (big endian)
    amdgcn     - AMD GCN GPUs
    arm        - ARM
    arm64      - ARM64 (little endian)
    armeb      - ARM (big endian)
    bpf        - BPF (host endian)
    bpfeb      - BPF (big endian)
    bpfel      - BPF (little endian)
    hexagon    - Hexagon
    mips       - Mips
    mips64     - Mips64 [experimental]
    mips64el   - Mips64el [experimental]
    mipsel     - Mipsel
    msp430     - MSP430 [experimental]
    nvptx      - NVIDIA PTX 32-bit
    nvptx64    - NVIDIA PTX 64-bit
    ppc32      - PowerPC 32
    ppc64      - PowerPC 64
    ppc64le    - PowerPC 64 LE
    r600       - AMD GPUs HD2XXX-HD6XXX
    sparc      - Sparc
    sparcel    - Sparc LE
    sparcv9    - Sparc V9
    systemz    - SystemZ
    thumb      - Thumb
    thumbeb    - Thumb (big endian)
    x86        - 32-bit X86: Pentium-Pro and above
    x86-64     - 64-bit X86: EM64T and AMD64
    xcore      - XCore
JohanEngelen commented 7 years ago

Master has same problem.

LLDB result:

(lldb) run -c gh2151.d
Process 14929 launched: '../bin/ldc2' (x86_64)
ldc2 was compiled with optimization - stepping may behave oddly; variables may not be available.
Process 14929 stopped
* thread #1: tid = 0xc3a03, 0x00000001002bd17f ldc2`(anonymous namespace)::DtoCallFunctionImpl(Loc&, Type*, DValue*, std::__1::vector<DValue*, std::__1::allocator<DValue*> > const&, llvm::Value*) + 56 at tocall.cpp:160, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
    frame #0: 0x00000001002bd17f ldc2`(anonymous namespace)::DtoCallFunctionImpl(Loc&, Type*, DValue*, std::__1::vector<DValue*, std::__1::allocator<DValue*> > const&, llvm::Value*) + 56 at tocall.cpp:160 [opt]
   157        irArg = irFty.args[i];
   158      }
   159  
-> 160      DValue *const argval = argvals[irArg->parametersIdx];
   161      Type *const argType = argval->type;
   162  
   163      llvm::Value *llVal = nullptr;
(lldb) bt
* thread #1: tid = 0xc3a03, 0x00000001002bd17f ldc2`(anonymous namespace)::DtoCallFunctionImpl(Loc&, Type*, DValue*, std::__1::vector<DValue*, std::__1::allocator<DValue*> > const&, llvm::Value*) + 56 at tocall.cpp:160, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
  * frame #0: 0x00000001002bd17f ldc2`(anonymous namespace)::DtoCallFunctionImpl(Loc&, Type*, DValue*, std::__1::vector<DValue*, std::__1::allocator<DValue*> > const&, llvm::Value*) + 56 at tocall.cpp:160 [opt]
    frame #1: 0x00000001002bd147 ldc2`(anonymous namespace)::DtoCallFunctionImpl(loc=0x00000001043058b8, resulttype=0x0000000104301310, fnval=<unavailable>, argvals=size=0, sretPointer=<unavailable>) + 1975 at tocall.cpp:854 [opt]
    frame #2: 0x00000001002be18d ldc2`DtoCallFunction(loc=0x00000001043058b8, resulttype=<unavailable>, fnval=<unavailable>, arguments=<unavailable>, sretPointer=<unavailable>) + 765 at tocall.cpp:1075 [opt]
    frame #3: 0x00000001002c41aa ldc2`ToElemVisitor::call(p=<unavailable>, e=<unavailable>, sretPointer=<unavailable>) + 1098 at toir.cpp:742 [opt]
    frame #4: 0x00000001002c93c4 ldc2`ToElemVisitor::visit(this=0x00007fff5fbfe258, e=<unavailable>) + 20 at toir.cpp:752 [opt]
    frame #5: 0x0000000100180be4 ldc2`CallExp::accept(Visitor*) + 52 at expression.d:10508
    frame #6: 0x00000001002c3bdd ldc2`toElemDtor(e=0x00000001043058b0) + 109 at toir.cpp:2719 [opt]
    frame #7: 0x00000001002ae460 ldc2`ToIRVisitor::visit(this=<unavailable>, stmt=<unavailable>) + 304 at statements.cpp:315 [opt]
    frame #8: 0x0000000100055cf1 ldc2`ExpStatement::accept(Visitor*) + 49 at statement.d:701
    frame #9: 0x00000001002ae5b4 ldc2`ToIRVisitor::visit(this=<unavailable>, stmt=<unavailable>) + 276 at statements.cpp:112 [opt]
    frame #10: 0x000000010005bde1 ldc2`CompoundStatement::accept(Visitor*) + 49 at statement.d:888
    frame #11: 0x00000001002ae2f8 ldc2`Statement_toIR(s=<unavailable>, irs=<unavailable>) + 40 at statements.cpp:1700 [opt]
    frame #12: 0x0000000100270e80 ldc2`DtoDefineFunction(fd=<unavailable>, linkageAvailableExternally=<unavailable>) + 5936 at functions.cpp:1082 [opt]
    frame #13: 0x0000000100117574 ldc2`FuncDeclaration::accept(Visitor*) + 52 at func.d:4268
    frame #14: 0x0000000100263872 ldc2`Declaration_codegen(Dsymbol*) [inlined] Declaration_codegen(decl=<unavailable>) + 50 at declarations.cpp:510 [opt]
    frame #15: 0x0000000100263852 ldc2`Declaration_codegen(decl=<unavailable>) + 18 at declarations.cpp:505 [opt]
    frame #16: 0x0000000100285af6 ldc2`codegenModule(irs=<unavailable>, m=<unavailable>) + 3574 at modules.cpp:725 [opt]
    frame #17: 0x0000000100307cd2 ldc2`ldc::CodeGenerator::emit(this=0x00007fff5fbfe988, m=0x0000000104304d90) + 210 at codegenerator.cpp:286 [opt]
    frame #18: 0x000000010032245f ldc2`codegenModules(modules=<unavailable>) + 239 at main.cpp:1068 [opt]
    frame #19: 0x00000001000f9bb4 ldc2`mars_mainBody(Array<char const*>&, Array<char const*>&) + 7124 at mars.d:1718
    frame #20: 0x000000010032197e ldc2`cppmain(argc=<unavailable>, argv=<unavailable>) + 9982 at main.cpp:1037 [opt]
    frame #21: 0x000000010000278a ldc2`_Dmain + 58 at main.d:35
    frame #22: 0x0000000101dc1fa2 ldc2`_D2rt6dmain211_d_run_mainUiPPaPUAAaZiZ6runAllMFZ9__lambda1MFZv + 34 at dmain2.d:474
    frame #23: 0x0000000101dc1e31 ldc2`_D2rt6dmain211_d_run_mainUiPPaPUAAaZiZ7tryExecMFMDFZvZv + 49 at dmain2.d:449
    frame #24: 0x0000000101dc1ef8 ldc2`_D2rt6dmain211_d_run_mainUiPPaPUAAaZiZ6runAllMFZv + 72 at dmain2.d:474
    frame #25: 0x0000000101dc1e31 ldc2`_D2rt6dmain211_d_run_mainUiPPaPUAAaZiZ7tryExecMFMDFZvZv + 49 at dmain2.d:449
    frame #26: 0x0000000101dc1d76 ldc2`_d_run_main + 982 at dmain2.d:482
    frame #27: 0x00000001000027d5 ldc2`main + 37 at __entrypoint.d:8
    frame #28: 0x00007fff8b4455ad libdyld.dylib`start + 1
    frame #29: 0x00007fff8b4455ad libdyld.dylib`start + 1
dnadlinger commented 7 years ago

Might be related to the implicit arguments for Dmain.

Ace17 commented 5 years ago

Still there:

$ ldc2 yo.d
/usr/lib/x86_64-linux-gnu/libLLVM-6.0.so.1(_ZN4llvm3sys15PrintStackTraceERNS_11raw_ostreamE+0x1a)[0x7f03b01bc71a]
/usr/lib/x86_64-linux-gnu/libLLVM-6.0.so.1(_ZN4llvm3sys17RunSignalHandlersEv+0x3e)[0x7f03b01ba7ee]
/usr/lib/x86_64-linux-gnu/libLLVM-6.0.so.1(+0x92097d)[0x7f03b01ba97d]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x12730)[0x7f03af87c730]
ldc2(_Z15DtoCallFunctionR3LocP4TypeP6DValueP5ArrayIP10ExpressionEPN4llvm5ValueE+0xb61)[0x5628e07db0f1]
ldc2(+0x6482dd)[0x5628e07e62dd]
ldc2(+0x64850f)[0x5628e07e650f]
ldc2(_Z10toElemDtorP10Expression+0x7e)[0x5628e07e2e4e]
ldc2(+0x630400)[0x5628e07ce400]
ldc2(+0x631d24)[0x5628e07cfd24]
ldc2(_Z14Statement_toIRP9StatementP7IRState+0x34)[0x5628e07cdca4]
ldc2(_Z17DtoDefineFunctionP15FuncDeclarationb+0xbe9)[0x5628e0793ec9]
ldc2(_Z19Declaration_codegenP7DsymbolP7IRState+0x34)[0x5628e078ab14]
ldc2(_Z13codegenModuleP7IRStateP6Module+0xed)[0x5628e07a9a1d]
ldc2(_ZN3ldc13CodeGenerator4emitEP6Module+0xa3)[0x5628e0851bc3]
ldc2(_Z14codegenModulesR5ArrayIP6ModuleE+0x197)[0x5628e0824c27]
ldc2(_Z13mars_mainBodyR5ArrayIPKcES3_+0x1ab0)[0x5628e06586c0]
ldc2(_Z7cppmainiPPc+0x1e2f)[0x5628e0827d2f]
ldc2(_D2rt6dmain211_d_run_mainUiPPaPUAAaZiZ6runAllMFZv+0x50)[0x5628e0985110]
ldc2(_d_run_main+0x1f6)[0x5628e0984f26]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xeb)[0x7f03af18c09b]
ldc2(_start+0x2a)[0x5628e05870ca]
[1]    2427 segmentation fault  ldc2 yo.d
$ ldc2 --version
LDC - the LLVM D compiler (1.12.0):
  based on DMD v2.082.1 and LLVM 6.0.1
  built with LDC - the LLVM D compiler (1.12.0)
  Default target: x86_64-pc-linux-gnu
  Host CPU: sandybridge
  http://dlang.org - http://wiki.dlang.org/LDC

  Registered Targets:
    aarch64    - AArch64 (little endian)
    aarch64_be - AArch64 (big endian)
    amdgcn     - AMD GCN GPUs
    arm        - ARM
    arm64      - ARM64 (little endian)
    armeb      - ARM (big endian)
    avr        - Atmel AVR Microcontroller
    bpf        - BPF (host endian)
    bpfeb      - BPF (big endian)
    bpfel      - BPF (little endian)
    hexagon    - Hexagon
    lanai      - Lanai
    mips       - Mips
    mips64     - Mips64 [experimental]
    mips64el   - Mips64el [experimental]
    mipsel     - Mipsel
    msp430     - MSP430 [experimental]
    nvptx      - NVIDIA PTX 32-bit
    nvptx64    - NVIDIA PTX 64-bit
    ppc32      - PowerPC 32
    ppc64      - PowerPC 64
    ppc64le    - PowerPC 64 LE
    r600       - AMD GPUs HD2XXX-HD6XXX
    sparc      - Sparc
    sparcel    - Sparc LE
    sparcv9    - Sparc V9
    systemz    - SystemZ
    thumb      - Thumb
    thumbeb    - Thumb (big endian)
    wasm32     - WebAssembly 32-bit
    wasm64     - WebAssembly 64-bit
    x86        - 32-bit X86: Pentium-Pro and above
    x86-64     - 64-bit X86: EM64T and AMD64
    xcore      - XCore
kinke commented 5 years ago

[This is of lowest priority to me; using a correct signature for D main if somehow really wanting to call it manually works: int main(string[] args); void f() { main([]); }]