[LLVMdev] Wrong calling convention?

Óscar Fuentes ofv at wanadoo.es
Tue Mar 25 23:23:54 PDT 2008

When my llvm code calls certain function, either it receives a wrong
result or the application ends on what it seems a corrupt stack.

The function is a C++ static method that returns a class with just a
`double' data member:

class Foo {
  double data;

My compiler abstracts this as a [8 x i8] array. This is the llvm code:

define internal i1 @Addr_045442A0() {
	alloca [8 x i8], align 4		; <[8 x i8]*>:1 [#uses=2]
	alloca i1, align 4		; <i1*>:2 [#uses=2]
	tail call void @F95478DA5_FFI_FN( [8 x i8]* %1 sret  )
	bitcast [8 x i8]* %1 to i8*		; <i8*>:3 [#uses=1]
	tail call void @Addr_004DDA18( i8* inttoptr (i32 14545104 to i8*), i8* %3 )
	store i1 true, i1* %2
	load i1* %2		; <i1>:4 [#uses=1]
	ret i1 %4

It is a function that just calls the above mentioned C++ static method,
calls another external function which is known to be "safe" (as it does
nothing and is called thousands of times everywhere without problems)
and returns bool.

This is the generated machine code, obtained with gdb:

0x0e8d9370:     push   %esi
0x0e8d9371:     sub    $0x18,%esp
0x0e8d9374:     lea    0x10(%esp),%esi
0x0e8d9378:     mov    %esi,(%esp)
0x0e8d937b:     call   0x5053b0 <_ZN3lp04OpF0IN5IncDB9TDateTimeEXadL_ZNS2_3NowEvEEE1wEv>
0x0e8d9380:     sub    $0x4,%esp
0x0e8d9383:     mov    %esi,0x4(%esp)
0x0e8d9387:     movl   $0x8def210,(%esp)
0x0e8d938e:     call   0x4b3ca0 <_ZN3lp015BasicDestructorIN5IncDB9TDateTimeEEEvRNS_8TipoInfoEPv>
0x0e8d9393:     movb   $0x1,0x8(%esp)
0x0e8d9398:     movzbl 0x8(%esp),%eax
0x0e8d939d:     add    $0x18,%esp
0x0e8d93a0:     pop    %esi
0x0e8d93a1:     ret

I'm using setCallingConv(CallingConv::C). After hours and hours of
debugging, I'm lost. Do you see something wrong here?

My setup is llvm 2.1 on Windows XPSP2. Everything is compiled with MinGW
g++.exe (GCC) 4.2.1-dw2 (mingw32-2)


More information about the llvm-dev mailing list