[LLVMdev] newbie question on getelementptr
Óscar Fuentes
ofv at wanadoo.es
Wed Sep 19 14:41:47 PDT 2012
Jay Gelisah <jay.gelisah at gmail.com> writes:
> However, if I replace the retrieved function ponter
>
> GenericValue GV = EE->runFunction(myfn, Args);
>
> with the original function pointer
> GenericValue GV = EE->runFunction(func_add, Args);
>
> It seems to run okay and prints the correct result.
>
> Here is the dump of my console:
>
> ===================================================================
> ; ModuleID = 'myModule'
> target datalayout =
> "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
> target triple = "x86_64-unknown-linux-gnu"
>
> %myStruct = type { i32 (i32, i32)* }
>
> @myGV = global %myStruct { i32 (i32, i32)* @add }
>
> define i32 @add(i32, i32) {
> Start:
> %sum = add i32 %0, %1
> ret i32 %sum
> }
>
> define void @dummy(i32) {
> EntryBlock:
> %1 = load i32 (i32, i32)** getelementptr inbounds (%myStruct* @myGV, i32
> 0, i32 0)
> ret void
> }
>
> type of myfn:i32 (i32, i32)*Bus error
> ===================================================================
>
> What am I doing wrong here?
Where do you set the value stored in the GlobalVariable before reading
it? With the getelementptr you are getting an address to uninitialized
memory. In C parlance, you are accessing an unitialized struct member.
More information about the llvm-dev
mailing list