[LLVMdev] strange code behavior when non-prototyped user function are called
Duncan Sands
baldrick at free.fr
Thu Sep 30 02:08:16 PDT 2010
Hi Chuck,
> However, if I comment out the first 2 lines (the prototype declarations),
> llvm-gcc will generate the following code for foo() instead:
> define void @foo() nounwind {
> entry:
> %0 = call i32 (...)* bitcast (void ()* @bar to i32 (...)*)() nounwind ; <i32>
> [#uses=0]
in C a prototype like this
void bar()
or no prototype at all means that bar takes a variable number of arguments
(corresponds to ... in the LLVM type); if there is no prototype then bar
is also considered to return i32.
So in foo, the call to bar is technically a call to a function of type i32
(...). However later the body of bar is output, at which point the type of
@bar is corrected to void (void). This results in a bitcast in the call.
The instcombine pass should clean this up.
Ciao,
Duncan.
More information about the llvm-dev
mailing list