From 8d6b19a518b68a045e3db4e06b3ddc5023ffd046 Mon Sep 17 00:00:00 2001 From: Wei Pan Date: Mon, 26 Aug 2013 14:27:34 +0000 Subject: Handle predefined expression for a captured statement - __func__ or __FUNCTION__ returns captured statement's parent function name, not the one compiler generated. Differential Revision: http://llvm-reviews.chandlerc.com/D1491 Reviewed by bkramer llvm-svn: 189219 --- clang/lib/AST/Expr.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'clang/lib/AST') diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp index 0ba117e3e2a..ea91fbec4f8 100644 --- a/clang/lib/AST/Expr.cpp +++ b/clang/lib/AST/Expr.cpp @@ -604,6 +604,16 @@ std::string PredefinedExpr::ComputeName(IdentType IT, const Decl *CurrentDecl) { Out.flush(); return Name.str().str(); } + if (const CapturedDecl *CD = dyn_cast(CurrentDecl)) { + for (const DeclContext *DC = CD->getParent(); DC; DC = DC->getParent()) + // Skip to its enclosing function or method, but not its enclosing + // CapturedDecl. + if (DC->isFunctionOrMethod() && (DC->getDeclKind() != Decl::Captured)) { + const Decl *D = Decl::castFromDeclContext(DC); + return ComputeName(IT, D); + } + llvm_unreachable("CapturedDecl not inside a function or method"); + } if (const ObjCMethodDecl *MD = dyn_cast(CurrentDecl)) { SmallString<256> Name; llvm::raw_svector_ostream Out(Name); -- cgit v1.2.3