[cfe-dev] How to go about generating wrapper functions when a particular attribute is seen?

John McCall via cfe-dev cfe-dev at lists.llvm.org
Wed Nov 15 20:14:34 PST 2017


> On Nov 15, 2017, at 10:32 PM, Seth Goldstein via cfe-dev <cfe-dev at lists.llvm.org> wrote:
> 
> I am wondering what the best approach would be to generate a wrapper
> function for functions with a particular attribute.  I.e.,
> 
> When the compiler sees
> 
> __attribute__ ((wrapthis)) int foo(args) {}
> 
> I want to generate foo as usual and also generate a function
> 
> int
> foo_wrapper(args)
> {
> 	// do some stuff here
> 	int result = foo(args);
> 	// do some more stuff here
> 	return result;
> }
> 
> I am not sure where to generate the wrapper function, e.g., in clang,
> in llvm?  And, what pass could I look at that might provide me with
> some hints about how to go about this.  Any help would be appreciated.

A feature like this could be implemented in many different ways, so it's hard to answer
your question without more basic information.  How are you anticipating this wrapper
function being used?  Are all existing uses of the function re-routed to it?  Is it important
that "ignorant" translation units use the wrapper function?  Is it important that ignorant
translation units not use the wrapper function?  What's the basic goal here?

John.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20171115/68e53b60/attachment-0001.html>


More information about the cfe-dev mailing list