From: Douglas Gregor Date: Tue, 6 Sep 2011 21:41:04 +0000 (+0000) Subject: When extracting the callee declaration from a call expression, be sure X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1ddc9c4674b7c737ec65241a531df8c64e40b0a9;p=clang When extracting the callee declaration from a call expression, be sure to look through SubstNonTypeTemplateParmExprs. Then, update the IR generation of CallExprs to actually use CallExpr::getCalleeDecl() rather than attempting to mimick its behavior (badly). Fixes . git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@139185 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AST/Expr.cpp b/lib/AST/Expr.cpp index 41fa850184..26ff6f3b7d 100644 --- a/lib/AST/Expr.cpp +++ b/lib/AST/Expr.cpp @@ -771,6 +771,12 @@ CallExpr::CallExpr(ASTContext &C, StmtClass SC, unsigned NumPreArgs, Decl *CallExpr::getCalleeDecl() { Expr *CEE = getCallee()->IgnoreParenCasts(); + + while (SubstNonTypeTemplateParmExpr *NTTP + = dyn_cast(CEE)) { + CEE = NTTP->getReplacement()->IgnoreParenCasts(); + } + // If we're calling a dereference, look at the pointer instead. if (BinaryOperator *BO = dyn_cast(CEE)) { if (BO->isPtrMemOp()) diff --git a/lib/CodeGen/CGExpr.cpp b/lib/CodeGen/CGExpr.cpp index d26d787da6..0be3628a62 100644 --- a/lib/CodeGen/CGExpr.cpp +++ b/lib/CodeGen/CGExpr.cpp @@ -2174,14 +2174,10 @@ RValue CodeGenFunction::EmitCallExpr(const CallExpr *E, if (const CXXMemberCallExpr *CE = dyn_cast(E)) return EmitCXXMemberCallExpr(CE, ReturnValue); - const Decl *TargetDecl = 0; - if (const ImplicitCastExpr *CE = dyn_cast(E->getCallee())) { - if (const DeclRefExpr *DRE = dyn_cast(CE->getSubExpr())) { - TargetDecl = DRE->getDecl(); - if (const FunctionDecl *FD = dyn_cast(TargetDecl)) - if (unsigned builtinID = FD->getBuiltinID()) - return EmitBuiltinExpr(FD, builtinID, E); - } + const Decl *TargetDecl = E->getCalleeDecl(); + if (const FunctionDecl *FD = dyn_cast_or_null(TargetDecl)) { + if (unsigned builtinID = FD->getBuiltinID()) + return EmitBuiltinExpr(FD, builtinID, E); } if (const CXXOperatorCallExpr *CE = dyn_cast(E)) diff --git a/test/CodeGenCXX/builtins.cpp b/test/CodeGenCXX/builtins.cpp index 0629c31015..4542563717 100644 --- a/test/CodeGenCXX/builtins.cpp +++ b/test/CodeGenCXX/builtins.cpp @@ -7,3 +7,15 @@ int main() { // CHECK: call signext i8 @memmove() return memmove(); } + +// + +template +int equal(const char *s1, const char *s2) { + return Compare(s1, s2) == 0; +} + +// CHECK: define weak_odr i32 @_Z5equalIXadL_Z16__builtin_strcmpPKcS1_EEEiS1_S1_ +// CHECK: call i32 @strcmp +template int equal<&__builtin_strcmp>(const char*, const char*); +