[llvm-dev] Cast a function parameter to GEP
Alberto Barbaro via llvm-dev
llvm-dev at lists.llvm.org
Sat Mar 9 00:34:41 PST 2019
Thanks Tim,
I'll keep using that notation for getting the value of str1 for now.
Thanks again for your help
On Sat, Mar 9, 2019, 07:42 Tim Northover <t.p.northover at gmail.com> wrote:
> On Sat, 9 Mar 2019 at 07:22, Alberto Barbaro <barbaro.alberto at gmail.com>
> wrote:
> > 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();
>
> > 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.
>
> If that one works it sounds like you don't have any kind of GEP at
> that point. Otherwise the cast to GlobalVariable would fail. Have you
> tried calling Module::dump while that code is executing to see what
> you're really dealing with?
>
> > I cast using GEPOperator *op = dyn_cast<GEPOperator>(CI->getOperand(0));
>
> That looks right to me if you have a GEP. Once you've got that you'd
> have to carefully check the operands of the GEP to make sure no-one is
> doing anything tricksy like
>
> printf(LocalVariable); //
> cast<GlobalVariable>(MyGEP->getPointerOperand) will fail so use
> dyn_cast and check the result.
> printf(&"MwahahahaHello world\n"[9]); // The GEP will have
> non-zero index operands. They may not even be constant.
>
> Cheers.
>
> Tim.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190309/b48187d6/attachment.html>
More information about the llvm-dev
mailing list