Wiki Roadmap Timeline Tickets New Ticket Source Search Help / Guide About Trac Login

Ticket #424 (new defect)

Opened 1 year ago

Last modified 1 year ago

Crash related to inlining and template functions

Reported by: klickverbot Assigned to: ChristianK
Priority: major Milestone:
Component: unspecified Version: hg tip
Keywords: Cc:

Description

LDC hg tip crashes on OS X 10.6 when trying to compile the following minimal example with inlining enabled.

$ cat ModuleA.d 
module ModuleA;

import ModuleB;
$ cat ModuleB.d 
module ModuleB;

void sel_registerName (char[] str) () {
}

void initWithTitle(char[] anAction) {
    sel_registerName!(anAction);
}
$ ldc -inline -c ModuleA.d
0  ldc               0x000000010090e6c9 PrintStackTrace(void*) + 38
1  ldc               0x000000010090ebc0 SignalHandler(int) + 336
2  libSystem.B.dylib 0x00007fff84d5935a _sigtramp + 26
3  libSystem.B.dylib 0x000000010253d030 _sigtramp + 2105425136
4  ldc               0x0000000100180d23 DtoDefineFunction(FuncDeclaration*) + 2682
5  ldc               0x00000001001d4f84 Ir::emitFunctionBodies() + 60
6  ldc               0x00000001001cffeb Module::genLLVMModule(llvm::LLVMContext&, Ir*) + 1069
7  ldc               0x00000001001962c5 main + 10344
8  ldc               0x00000001000789b4 start + 52
Segmentation fault

Change History

08/20/10 19:27:04 changed by klickverbot

Oh, I forgot to mention, the stacktrace printed is misleading. Here is what GDB yields:

Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_INVALID_ADDRESS at address: 0x0000000000000058
0x000000010019c1d6 in DtoCreateNestedContext (fd=0x10253d030) at /Build/Source/ldc/gen/nested.cpp:537
537	            fd->ir.irFunc->frameType = parFunc->ir.irFunc->frameType;
(gdb) bt
#0  0x000000010019c1d6 in DtoCreateNestedContext (fd=0x10253d030) at /Build/Source/ldc/gen/nested.cpp:537
#1  0x0000000100180d23 in DtoDefineFunction (fd=0x10253d030) at /Build/Source/ldc/gen/functions.cpp:755
#2  0x00000001001d4f84 in Ir::emitFunctionBodies (this=0x7fff5fbff630) at /Build/Source/ldc/ir/ir.cpp:32
#3  0x00000001001cffeb in Module::genLLVMModule (this=0x102510840, context=@0x10252e3f0, sir=0x7fff5fbff630) at /Build/Source/ldc/gen/toobj.cpp:145
#4  0x00000001001962c5 in main (argc=4, argv=0x7fff5fbff988) at /Build/Source/ldc/gen/main.cpp:933

08/20/10 19:29:13 changed by klickverbot

According to bioinformatics, the same crash occurs on Linux x86_64.

08/21/10 18:38:37 changed by klickverbot

If I remember correctly from my debugging session some days ago, the problem here is that the DSymbol::parent for the template instance (sel_registerName!(anAction)) is the function which instantiates it (initWithTitle), and not ModuleB. Thus, the call to getParentFunc(fd, true) at gen/nested.cpp:535 (while sel_registerName is processed) yields initWithTitle, which in turn leads to the null pointer access, because it has not been codegen'd yet (parFunc->ir.irFunc is 0).

Any ideas what could be the root cause here?

08/23/10 12:39:16 changed by fawzi

For me the code is invalid, passing an argument of a function to a template is not something that is supposed to work. Thus (at least the reduced case) is ICE on invalid, it should probably spit out an error like: cannot use runtime argument at compile time.

The clean way would probably be to pass anAction as compile-time argument, CTFE is not supposed to handle these things...

08/23/10 13:24:19 changed by klickverbot

Although I have not noticed this for all the time (did I hear anybody mentioning forests and trees?), I also think that this is a accepts-invalid bug in DMDFE and would suggest waiting until this is fixed in the frontend.

Copyright © 2008, LDC Development Team.