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

Taddeus via cfe-users cfe-users at lists.llvm.org
Thu May 4 04:50:21 PDT 2017


Hi all,

I want to annotate malloc(sizeof(X)) 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-users/attachments/20170504/4b2895c4/attachment.html>


More information about the cfe-users mailing list