[LLVMdev] Why function pointer is different from other data type?

Chris Lattner clattner at apple.com
Mon Apr 12 09:25:55 PDT 2010


On Apr 12, 2010, at 8:02 AM, Hao Shen wrote:

> Dear all,
> 
> I compiled c program with llvm and found something strange with
> function pointer as following small example .
> 
> ------------- In C Code --------------
> float a (int value) {
>    return value + 1;
> };
> 
> typedef float (*funcptr_t) (int);
> 
> funcptr_t get_ptr(funcptr_t p) {
>    return p;
> }
> 
> float result = get_ptr(a)(4);
> 
> ------------- In LLVM Code --------------
> 
> %4 = call float (i32)* (float (i32)*)* @get_ptr(float (i32)* @a1)
> nounwind 
>            ~~~~~~~~~~~~~~~~~~~~  VERY STRANGE RETURN TYPE !!!
> %5 = call float %4(i32 4) nounwind              ; <float> [#uses=1]


These two are equivalent in the .ll file syntax:
  call void @foo()
and:
  call void()* @foo()

The .ll printer uses the first when it can because it is cleaner and easier to read.  It can't do this for varargs and for functions returning a pointer to a function (because of ambiguity issues).

-Chris



More information about the llvm-dev mailing list