[LLVMdev] GetElementPtrInst Again!

Chris Lattner sabre at nondot.org
Fri Nov 21 16:20:01 PST 2003


On Fri, 21 Nov 2003, Reid Spencer wrote:
> I'm trying to set up a call to printf in stacker and have managed to
> confuse myself. Perhaps you can shed some light.

:)

> I've declared printf as a function taking a pointer to SByteTy with var
> args and returning SIntTy:

Sounds good.

> When I set up the call, I get the following from that pesky :) verifier:

Ah, but it's so helpful!  :)

> Call parameter type does not match function signature!
>         getelementptr [3 x sbyte]* %_str_format_, long 0                ; <[3 x sbyte]*>:0 [#uses=1]
> typesbyte* sbyte *
>
> So, in LLVM are arrays and pointers not equivalent as in "C"?

Absolutely not.

> What do I have to do to turn my little str_format array into a pointer?

Try making a: getelementptr [3 x sbyte]* %_str_format_, long 0, long 0

This means:
   [3 x sbyte]* %_str_format_,      ; Start from _str_format_
   long 0,                          ; Get the first [3 x sbyte] array pointed to
   long 0                           ; Get the first element in the array

Also, you can try plunking the equivalent code into the C frontend (either
manually or through the demo page) to see what it makes, if you get
confused.  :)

-Chris

-- 
http://llvm.cs.uiuc.edu/
http://www.nondot.org/~sabre/Projects/




More information about the llvm-dev mailing list