[cfe-commits] r139185 - in /cfe/trunk: lib/AST/Expr.cpp lib/CodeGen/CGExpr.cpp test/CodeGenCXX/builtins.cpp
Eli Friedman
eli.friedman at gmail.com
Tue Sep 6 15:15:08 PDT 2011
On Tue, Sep 6, 2011 at 2:41 PM, Douglas Gregor <dgregor at apple.com> wrote:
> Author: dgregor
> Date: Tue Sep 6 16:41:04 2011
> New Revision: 139185
>
> URL: http://llvm.org/viewvc/llvm-project?rev=139185&view=rev
> Log:
> 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 <rdar://problem/10063539>.
>
>
> Modified:
> cfe/trunk/lib/AST/Expr.cpp
> cfe/trunk/lib/CodeGen/CGExpr.cpp
> cfe/trunk/test/CodeGenCXX/builtins.cpp
>
> Modified: cfe/trunk/lib/AST/Expr.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=139185&r1=139184&r2=139185&view=diff
> ==============================================================================
> --- cfe/trunk/lib/AST/Expr.cpp (original)
> +++ cfe/trunk/lib/AST/Expr.cpp Tue Sep 6 16:41:04 2011
> @@ -771,6 +771,12 @@
>
> Decl *CallExpr::getCalleeDecl() {
> Expr *CEE = getCallee()->IgnoreParenCasts();
> +
> + while (SubstNonTypeTemplateParmExpr *NTTP
> + = dyn_cast<SubstNonTypeTemplateParmExpr>(CEE)) {
> + CEE = NTTP->getReplacement()->IgnoreParenCasts();
> + }
> +
> // If we're calling a dereference, look at the pointer instead.
> if (BinaryOperator *BO = dyn_cast<BinaryOperator>(CEE)) {
> if (BO->isPtrMemOp())
The Ignore* methods are really a mess at the moment... should some/all
of them look through SubstNonTypeTemplateParmExpr?
> Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=139185&r1=139184&r2=139185&view=diff
> ==============================================================================
> --- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
> +++ cfe/trunk/lib/CodeGen/CGExpr.cpp Tue Sep 6 16:41:04 2011
> @@ -2174,14 +2174,10 @@
> if (const CXXMemberCallExpr *CE = dyn_cast<CXXMemberCallExpr>(E))
> return EmitCXXMemberCallExpr(CE, ReturnValue);
>
> - const Decl *TargetDecl = 0;
> - if (const ImplicitCastExpr *CE = dyn_cast<ImplicitCastExpr>(E->getCallee())) {
> - if (const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(CE->getSubExpr())) {
> - TargetDecl = DRE->getDecl();
> - if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(TargetDecl))
> - if (unsigned builtinID = FD->getBuiltinID())
> - return EmitBuiltinExpr(FD, builtinID, E);
> - }
> + const Decl *TargetDecl = E->getCalleeDecl();
> + if (const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(TargetDecl)) {
> + if (unsigned builtinID = FD->getBuiltinID())
> + return EmitBuiltinExpr(FD, builtinID, E);
> }
>
> if (const CXXOperatorCallExpr *CE = dyn_cast<CXXOperatorCallExpr>(E))
Can we somehow catch cases where we end up taking the address of a
builtin instead of calling it?
-Eli
More information about the cfe-commits
mailing list