[LLVMdev] How to get the string value?

Duncan Sands baldrick at free.fr
Sat Jan 28 06:41:23 PST 2012


Hi Welson,

> Yes, it is a ConstantExpr! Thank you!
>
> Now trying to find a clue in ConstantExpr's functions to get that string :-)

you can get the pointer operand by doing: getOperand(0)
The i'th index is getOperand(i+1).

Ciao, Duncan.

>
> Regards,
> Welson
>
> On Thu, Jan 26, 2012 at 9:04 PM, Duncan Sands <baldrick at free.fr
> <mailto:baldrick at free.fr>> wrote:
>
>     Hi Welson Sun,
>
>      > Hi, if I have some LLVM code like this:
>      >
>      > @.str = private unnamed_addr constant [7 x i8] c"in_arr\00", align 1
>      > @.str1 = private unnamed_addr constant [8 x i8] c"in_arr2\00", align 1
>      > @.str2 = private unnamed_addr constant [8 x i8] c"out_arr\00", align 1
>      > ...
>      > ...
>      >
>      >    call void (...)* @_Z16fooz(i8* *getelementptr inbounds ([7 x i8]*
>     @.str, i64
>      > 0, i64 0)*, i32 0, i32 1024)
>      > ...
>      >
>      > I would like to get the string value of the bold argument, but how? I
>     know it's
>      > a llvm::Value pointer, but it is not a llvm::GetElementPtrInst?
>
>     it is a ConstantExpr getelementptr.  Whenever you see something that looks like
>     an instruction but is printed inline inside another instruction then that means
>     it is actually a constant, a ConstantExpr.
>
>     Ciao, Duncan.
>
>      >
>      >
>      > Thanks,
>      >
>      >
>      >
>      >
>      >
>      >
>      >
>      >
>      > _______________________________________________
>      > LLVM Developers mailing list
>      > LLVMdev at cs.uiuc.edu <mailto:LLVMdev at cs.uiuc.edu> http://llvm.cs.uiuc.edu
>      > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>
>     _______________________________________________
>     LLVM Developers mailing list
>     LLVMdev at cs.uiuc.edu <mailto:LLVMdev at cs.uiuc.edu> http://llvm.cs.uiuc.edu
>     http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>
>
>
>
> --
> Welson
>
> Phone: (408) 418-8385
> Email: welson.sun at gmail.com <mailto:welson.sun at gmail.com>
>
>




More information about the llvm-dev mailing list