[LLVMdev] Cloning a FunctionDecl?
Eli Friedman
eli.friedman at gmail.com
Tue Mar 27 17:44:45 PDT 2012
On Tue, Mar 27, 2012 at 4:08 PM, Dillon Sharlet <dsharlet at gmail.com> wrote:
> Hello,
>
> Is there a way to clone a FunctionDecl, including the body Stmt if it
> exists? I want to add an entirely new decl to the AST with its own copy of
> the body. I would like to start with a completely identical Decl and body,
> and then modify it to produce a new overload, such that this cloned function
> would appear in overload resolution for calls to the original function.
There is code inside Sema to do something like this as part of
template instantiation; see TreeTransform.h . It isn't exposed outside
of Sema, though,
> What I want to do is somewhat similar to template instantiation, but I've
> been looking through this mechanism and it *appears* that function templates
> don't actually duplicate the body of the function until LLVM code gen, is
> that true?
No, the instantiated function exists independently in the AST.
cfe-dev would be a better list for followup questions.
-Eli
More information about the llvm-dev
mailing list