[cfe-dev] Generation of CallExpr to builtin function

Abramo Bagnara abramobagnara at tin.it
Tue Oct 6 00:42:23 PDT 2009


Douglas Gregor ha scritto:
> 
> On Oct 5, 2009, at 7:54 AM, Abramo Bagnara wrote:
> 
>>
>> In our application we need to generate a new CallExpr to a builtin
>> function, but we are unable to find a way to do that.
>>
>> In SemaDecl.cpp we have found
>>
>> /// LazilyCreateBuiltin - The specified Builtin-ID was first used at
>> /// file scope.  lazily create a decl for it. ForRedeclaration is true
>> /// if we're creating this built-in in anticipation of redeclaring the
>> /// built-in.
>> NamedDecl *Sema::LazilyCreateBuiltin(IdentifierInfo *II, unsigned bid,
>>                                     Scope *S, bool ForRedeclaration,
>>                                     SourceLocation Loc);
>>
>> but it's inaccessible (and does also other things).
>>
>> What's the right way to do that?
> 
> You can find the built-in function using Sema::ActOnIdentifierExpr,
> which will have the effect of implicitly declaring the builtin (or
> finding it if it already existed) and then building a DeclRefExpr that
> you can use as the callee of your call expression.

Sorry, I think I have not explained well the problem.

What we need is a way for a program that uses clang as a library to
create a CallExpr to a builtin function.

Of course inside clang we would be able to use Sema to do that, but this
is not the case.

I think that having something similar to

NamedDecl* ASTContext::BuiltinDecl(IdentifierInfo *II, Builtin::ID BID);

could be a solution.




More information about the cfe-dev mailing list