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:> // Create a function for output (int printf(format,...)) > std::vector<Type*> params; > params.push_back( PointerType::get( Type::SByteTy ) ); > FunctionType* printf_type = FunctionType::get( Type::IntTy, params, true ); > ThePrintf = new Function( printf_type, GlobalValue::ExternalLinkage, > "printf", TheModule); >When I set up the call, I get the following from that pesky :) verifier: 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"? What do I have to do to turn my little str_format array into a pointer? I tried the FunctionType with an argument of [3 x sbyte] but that led to much worse diagnostics. Help! :) Reid. -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 189 bytes Desc: This is a digitally signed message part URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20031121/83470248/attachment.sig>
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/
On Fri, 2003-11-21 at 14:35, Chris Lattner wrote:> On Fri, 21 Nov 2003, Reid Spencer wrote: > > When I set up the call, I get the following from that pesky :) verifier: > > Ah, but it's so helpful! :)It is actually. It is ensuring that my compiler is correct which is one of the hardest things to do!> > So, in LLVM are arrays and pointers not equivalent as in "C"? > > Absolutely not.Aha!> > > 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 >Okay, so getelementptr gives you a pointer to the last thing indexed, right? So, if I just use a single long 0 operand on a global array, I get a pointer to an array in its entirety. That is the pointer type is [count x type]. If I use two long 0 operands, I get a pointer to the first element of the array so that the type of the pointer is just "type". I had assumed that, since the address of the 0th element of an array and the address of the array are the same that this equivalence would be recognized. But, apparently not. I can see why, however, a pointer to the whole array and a pointer to its first element differ in their type, even though the pointer values are the same. Am I getting this now?> 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. :) >Excellent idea .. I won't have to bug you as much :) Reid. -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 189 bytes Desc: This is a digitally signed message part URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20031121/6d662ece/attachment.sig>