[cfe-dev] Source transformations in frontend plugin before compilation

Jakub Kuderski via cfe-dev cfe-dev at lists.llvm.org
Fri May 5 09:12:31 PDT 2017


Taddeus,

Maybe you will find this thread useful: [cfe-dev] AST modifications that
apply to the binary
http://lists.llvm.org/pipermail/cfe-dev/2016-November/051668.html

~Jakub

On 4 May 2017 at 13:58, Taddeus via cfe-dev <cfe-dev at lists.llvm.org> wrote:

> Hi all,
>
> I want to annotate malloc(sizeof(ty)) calls with the type in the sizeof so
> that I can use the information in the IR later on (in a transformation
> plugin). My current approach is to do a somewhat hacky source
> transformation, replacing the call with:
>   malloc(({ ty * volatile ptr = NULL; (size_t)(ptr + 1); }))
> so that I can take the pointer type and replace the size back with a
> constant in the IR.
>
> If someone can think of a better way to do this inside a clang frontend
> plugin, I'm open to that, but currently I'm having issues just getting this
> to work. I have a working plugin that finds the sizeof expressions and a
> Rewriter instance that replaces them. However, I don't know how to apply
> the changes to the input file so that the input with be parsed again before
> being passed on to the codegen. There is a Reparse function in ASTUnit, but
> I cannot find (in the docs or online) how this is supposed to be used.
> Does anyone know how to correctly use this?
>
> Cheers,
> TaddeĆ¼s
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>
>


-- 
Jakub Kuderski
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20170505/e0c080cd/attachment.html>


More information about the cfe-dev mailing list