[cfe-dev] AST transformations in a plugin

David Blaikie dblaikie at gmail.com
Thu Jan 24 11:37:09 PST 2013


On Thu, Jan 24, 2013 at 11:22 AM, JohnH <jan.hoogerbrugge at gmail.com> wrote:
> Hi,
>
> For my instrumentation I would like to stay close to the source code so that
> I can report with accurate line / column numbers and refer to source level
> language constructs.

ubsan does this

> So is this feasible to do in a clang plugin or is rewriting AST a very complex thing to do?

It's just going to be more complicated, I think, than modifying IRGen
for your task. The extra indirection of producing source code (that
you have to make correct - finding unique names for any newly
introduced variables, etc) when all you want is new machine code to be
produced, is probably not going to do you any favors.

> Examples of what I would like to do is to add a function call before every
> loop and adding function calls for every array access.
>
>    for(...)
>      ;
>
> becomes:
>
>    here_comes_a_for_loop(...)
>    for(...)
>       ;
>
> and
>
>   a[b[i]]
>
> becomes:
>
>   a[array_index(..., b[array_index(..., i)]]

Sure, these are certainly things that ubsan does already (well, the
latter certainly - since ubsan does same simple array bounds checking
(this was already in Clang as -fcatch-undefined-behavior prior to the
recent ubsan efforts, I believe))

>
> Regards,
> John
>
>
>
> --
> View this message in context: http://clang-developers.42468.n3.nabble.com/AST-transformations-in-a-plugin-tp4029993p4030022.html
> Sent from the Clang Developers mailing list archive at Nabble.com.
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev



More information about the cfe-dev mailing list