[cfe-dev] want to intercept array dereferences

Gry Gunvor gry.gunvor at gmail.com
Thu Apr 9 10:31:32 PDT 2015


On Thu, Apr 9, 2015 at 3:44 AM, David Chisnall
<David.Chisnall at cl.cam.ac.uk> wrote:
> On 8 Apr 2015, at 17:56, Gry Gunvor <gry.gunvor at gmail.com> wrote:
>>
>> The LLVM guys suggest that intercepting a pointer type plus an int
>> type followed by a deref would not be a stable solution.  They suggest
>> that I do this at the clang layer.  Where would be the stable place to
>> do it?  I'm new to clang development, so some context would be
>> helpful.
>
> I think that your last sentence applies to everyone else too:

All are noobies!  In the future, technology is moving so fast that no
one knows anything.

> can you explain what you are trying to achieve?  In C, it is perfectly valid to write a[n], n[a], or *(a+n).  Do you want to distinguish these three or catch all of them?  What problem are you actually trying to solve?

Well as I said initially, I want to intercept base pointer + offset
data accesses, no matter which of those forms it is in.  So if the
front end converted a[n] to *(a+n) internally and then I intercepted
it, that would be fine.

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
not produce a stable result, depending on what the optimizer did and
that I should look in the front-end for how to intercept a[n].
Although, I'm thinking if I did it before any optimization passes, it
seems to me it should work.

So now I'm thinking that perhaps in the front-end there might be a
stage where a[n] has been lowered to *(a+n) and then I could just look
for an abstract syntax subtree of the form *(a+n) and replace that
with a different subtree.  Some suggestion as to a stable way to do
that would be great.

Gry



More information about the cfe-dev mailing list