[LLVMdev] First class function pointers
Chris Lattner
clattner at apple.com
Thu Feb 5 20:37:41 PST 2009
On Feb 5, 2009, at 8:32 PM, Jon Harrop wrote:
> On Friday 06 February 2009 03:33:57 Chris Lattner wrote:
>> On Feb 5, 2009, at 3:42 PM, Jon Harrop wrote:
>>> Unless I am mistaken, LLVM barfs if I try to pass an LLVM function
>>> to another
>>> function as an argument because functions are second class.
>>
>> Huh? can you give an example as llvm IR? You can certainly pass
>> functions by-value as a function pointer.
>
> Sorry, I seem to have confused myself. I was const bitcasting the
> function to
> a function pointer but that is redundant, presumably because the value
> returned when you define a function already represents a function
> pointer.
>
> Anyway, I still do not understand why functions are not listed as
> first-class
> types in the documentation if values of the "function" type can be
> produced
> by instructions, passed as arguments and used as operands to
> instructions?
"function types" are not first class values because you can't get one,
store one, or do anything with one. All functions are referred to via
pointer, and all pointer types are first class, including function
pointers. If you refer to a function with @foo, you're getting a
function pointer, not the function itself.
-Chris
More information about the llvm-dev
mailing list