[LLVMdev] convert GetElemtPtr result to pointer on element?

Tim Northover t.p.northover at gmail.com
Tue May 26 13:36:48 PDT 2015


> But I can not succeed in using the getGetElementPtr result in constructing
> an initalizer for another global value (which expects a ConstantFP* and not
> a ConstantExpr*).

The result of a Constant GEP is going to be the address of a
floating-point value rather than the value itself, so you can't use it
to initialise something that expects a float. For example:

    @arr = constant [2 x float] [float 0.0, float 1.0]
    @bad = global float getelementptr([2 x float], [2 x float]* @arr,
i32 0, i32 1)
    @good = global float* getelementptr([2 x float], [2 x float]*
@arr, i32 0, i32 1)

LLVM doesn't really do value aliases, so you'd usually just write
"@bad = global float 1.0" for the second line. You might extract that
1.0 value by looking into the @arr definition directly using the LLVM
API -- if you can't do that (say because it's not a compile-time
constant) then the chances are what you're trying to write wouldn't be
valid anyway.

Cheers.

Tim.



More information about the llvm-dev mailing list