<div dir="ltr"><div dir="ltr"><div dir="ltr"><div>Sorry Tim,</div><div>I now need to find the value of the constant expression and I found online a solution like: string value = cast<ConstantDataArray>(cast<GlobalVariable>(CallInstruction->getOperand(0))->getInitializer())->getAsCString();</div><div><br></div><div>This one works but I feel the GEPOperator should be used based on your comments, so I tried to cast the operator and get the value but I'm not able to do it.</div><div><br></div><div>I cast using GEPOperator *op = dyn_cast<GEPOperator>(CI->getOperand(0));<br></div><div><br></div><div>Could you tell me if it is correct and how to extract the value please?</div><div><br></div><div>Thanks <br></div></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Il giorno sab 9 mar 2019 alle ore 06:26 Alberto Barbaro <<a href="mailto:barbaro.alberto@gmail.com">barbaro.alberto@gmail.com</a>> ha scritto:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="auto">Thanks Tim,<div dir="auto">I'll try to solve my problem ASAP, if I cannot maybe I'll some other clarifications.</div><div dir="auto"><br></div><div dir="auto">Thanks again</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, Mar 9, 2019, 06:03 Tim Northover <<a href="mailto:t.p.northover@gmail.com" target="_blank">t.p.northover@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi Alberto,<br>
<br>
On Sat, 9 Mar 2019 at 05:50, Alberto Barbaro via llvm-dev<br>
<<a href="mailto:llvm-dev@lists.llvm.org" rel="noreferrer" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<br>
> i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str1, i32 0, i32 0)<br>
<br>
Because all of its inputs are Constants, this is actually a<br>
GetElementPtrConstantExpr instead of a GetElementPtrInst (the easiest<br>
way to tell on sight without context is the extra parens, which the<br>
instruction variant never has).<br>
<br>
The main practical difference between the two is that instances of<br>
Constant don't live in a BasicBlock independently, but are referenced<br>
directly by each user. When printing the IR this is shown by<br>
"inlining" them into the parent Instruction.<br>
<br>
LLVM has a GEPOperator class to help deal with this issue; it can be<br>
used to access the common features of Instructions and Constants.<br>
There are similar Operators for other operations because this is quite<br>
a common situation.<br>
<br>
> I think it does not work because str1 is a "private constant". Is there a way to solve it?<br>
<br>
Broadly true, but the same would apply to any global, not just ones<br>
declared constant.<br>
<br>
Cheers.<br>
<br>
Tim.<br>
</blockquote></div>
</blockquote></div>