[cfe-dev] Indirect call generation for other than native targets

ihusar at fit.vutbr.cz ihusar at fit.vutbr.cz
Tue Jan 29 01:05:02 PST 2013


Hello everyone,

   I encountered a behavior I don't quite understand in clang release 3.2  
and I could not find any responses anywhere, so I would like to ask here.

As an example, I have a simple program such as this one:

void fun();

int main()
{

	fun();

	return 0;
}


No, when i run

clang test.c -emit-llvm -S -o i86_64.ll

i get this LLVM IR code which is what I would expect:

; ModuleID = 'test.c'
target datalayout =  
"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

define i32 @main() nounwind uwtable {
entry:
   %retval = alloca i32, align 4
   store i32 0, i32* %retval
   call void (...)* @fun()
   ret i32 0
}

declare void @fun(...)


However, when I run clang like this with i386 target (or mips, or other  
targets):

clang test.c -target i386 -emit-llvm -S -o i386.ll

The caal to fun is indirect:

; ModuleID = 'test.c'
target datalayout =  
"e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32-S128"
target triple = "i386"

define i32 @main() nounwind {
entry:
   %retval = alloca i32, align 4
   store i32 0, i32* %retval
   call void bitcast (void (...)* @fun to void ()*)()
   ret i32 0
}

declare void @fun(...)


Please, what is the reason of this behavior, is it intentional? How can i  
make the nonnaticve targets generate direct calls?

Thank you
   Adam Husar



More information about the cfe-dev mailing list