[cfe-dev] want to intercept array dereferences
Jonathan Roelofs
jonathan at codesourcery.com
Thu Apr 9 11:24:22 PDT 2015
On 4/9/15 11:59 AM, Gry Gunvor wrote:
> On Thu, Apr 9, 2015 at 10:47 AM, Jonathan Roelofs
> <jonathan at codesourcery.com> wrote:
>>> Again, I asked the LLVM list if, since LLVM is a typed assembly
>>> language, if I could just look for pointer plus offset followed by a
>>> dereference. They seemed to suggest that looking for that idiom would
>
>> JFTR, we're one big community, and it's not as segregated into "the clang
>> devs" vs "the llvm devs" as you might think.
>
> On the LLVM list I was told "That would need to be in Clang" so I am
> writing the front-end list.
>
>> It's encouraged to cc both lists (as appropriate) when having these sorts of
>> discussions that span the interface between the two projects. This helps
>> give context to statements like "well I asked the other list", without
>> having to dig for that other message. At the very least you should provide a
>> link to the other discussion.
>
> Ok, in the future I will write both list, but I initially thought it
> was a purely backend question. The other discussion starts here:
> http://lists.cs.uiuc.edu/pipermail/llvmdev/2015-April/084280.html
>
> So now that I am writing both lists: where can I intercept a
> Clang/LLVM compile that will catch expressions that locally look like
> a[n] or *(a+n) ?
CodeGen for the former happens in
CodeGenFunction::EmitArraySubscriptExpr(). For the latter, you'll need
to look for UO_Deref in EmitUnaryOpLValue(), and work backwards up the
AST to find the BinOp for the +. This might be a little tricky as not
every dereference will have that addition binop as its child node, and
not every one that you find there is actually a case of array indexing.
>
> My guess is sometime after a[n] is lowered to *(a+n) (if you do that)
> and sometime before optimization passes start chewing on it.
As Bruce told you in the other thread, it's probably too late to look
for it in llvm. The best place really is to do it in Clang, though it
might depend on why you want to do this particular transformation. If
you're trying to do bounds checking, the sanitizers already do that.
Jon
>
> Gry
>
--
Jon Roelofs
jonathan at codesourcery.com
CodeSourcery / Mentor Embedded
More information about the cfe-dev
mailing list