[LLVMdev] mixing static/dynamic code
Nick Lewycky
nicholas at mxc.ca
Sun May 24 13:15:33 PDT 2009
Paul Martin wrote:
> Hi,
> I have the following code, the lines preceded by `>` being added at
> runtime (the snipped was also printed at runtime)
>
> define i32 @myfunc(i32 %pi) {
> entry:
> %pi_addr = alloca i32 ; <i32*> [#uses=3]
> %retval = alloca i32 ; <i32*> [#uses=2]
> %tmp = alloca i32 ; <i32*> [#uses=2]
> > %ptr32 = alloca i32 ; <i32*> [#uses=2]
> %"alloca point" = bitcast i32 0 to i32 ; <i32> [#uses=0]
>
> > store i32 %pi, i32* %ptr32
> > %ptr8 = bitcast i32* %ptr32 to i8* ; <i8*> [#uses=1]
> > call void @roc( i8* %ptr8 )
>
> store i32 %pi, i32* %pi_addr
> %pi_addr1 = bitcast i32* %pi_addr to i8* ; <i8*>
> [#uses=1]
> call void @roc( i8* %pi_addr1 )
> ...
>
> void roc(void*) is a function that only prints its argument as an integer.
So it's printing the pointer.
> I was expecting for the program to print the same thing twice (the
> address of the myfunc argument) because the code added at runtime looks
> to me identical with the code that was compiled (3 lines each).
> However, that was not the case; what I got was:
>
> 147156320
> 147117168
>
> What am I missing?
Make roc() dereference the pointers it's given and print that instead.
Nick
More information about the llvm-dev
mailing list