[PATCH] Handle captured statements for predefined expressions
Wei Pan
wei.pan at intel.com
Fri Aug 23 13:49:06 PDT 2013
Handle predefined expression differently from blocks
Hi bkramer,
http://llvm-reviews.chandlerc.com/D1491
CHANGE SINCE LAST DIFF
http://llvm-reviews.chandlerc.com/D1491?vs=3707&id=3713#toc
Files:
lib/AST/Expr.cpp
lib/CodeGen/CGExpr.cpp
lib/Sema/SemaExpr.cpp
test/SemaCXX/predefined-expr.cpp
Index: lib/AST/Expr.cpp
===================================================================
--- lib/AST/Expr.cpp
+++ lib/AST/Expr.cpp
@@ -604,6 +604,16 @@
Out.flush();
return Name.str().str();
}
+ if (const CapturedDecl *CD = dyn_cast<CapturedDecl>(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<ObjCMethodDecl>(CurrentDecl)) {
SmallString<256> Name;
llvm::raw_svector_ostream Out(Name);
Index: lib/CodeGen/CGExpr.cpp
===================================================================
--- lib/CodeGen/CGExpr.cpp
+++ lib/CodeGen/CGExpr.cpp
@@ -1972,6 +1972,10 @@
// Blocks use the mangled function name.
// FIXME: ComputeName should handle blocks.
FunctionName = FnName.str();
+ } else if (isa<CapturedDecl>(CurDecl)) {
+ // For a captured statement, the function name is its enclosing
+ // function name not the one compiler generated.
+ FunctionName = PredefinedExpr::ComputeName(IdentType, CurDecl);
} else {
FunctionName = PredefinedExpr::ComputeName(IdentType, CurDecl);
assert(cast<ConstantArrayType>(E->getType())->getSize() - 1 ==
Index: lib/Sema/SemaExpr.cpp
===================================================================
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -2765,6 +2765,8 @@
currentDecl = BSI->TheDecl;
else if (const LambdaScopeInfo *LSI = getCurLambda())
currentDecl = LSI->CallOperator;
+ else if (const CapturedRegionScopeInfo *CSI = getCurCapturedRegion())
+ currentDecl = CSI->TheCapturedDecl;
else
currentDecl = getCurFunctionOrMethodDecl();
Index: test/SemaCXX/predefined-expr.cpp
===================================================================
--- test/SemaCXX/predefined-expr.cpp
+++ test/SemaCXX/predefined-expr.cpp
@@ -37,4 +37,29 @@
static_assert(sizeof(__PRETTY_FUNCTION__) == 1, "__main_block_invoke");
}
();
+
+ #pragma clang __debug captured
+ {
+ static_assert(sizeof(__func__) == 5, "main");
+ static_assert(sizeof(__FUNCTION__) == 5, "main");
+ static_assert(sizeof(__PRETTY_FUNCTION__) == 11, "int main()");
+
+ #pragma clang __debug captured
+ {
+ static_assert(sizeof(__func__) == 5, "main");
+ static_assert(sizeof(__FUNCTION__) == 5, "main");
+ static_assert(sizeof(__PRETTY_FUNCTION__) == 11, "int main()");
+ }
+ }
+
+ []() {
+ #pragma clang __debug captured
+ {
+ static_assert(sizeof(__func__) == 11, "operator()");
+ static_assert(sizeof(__FUNCTION__) == 11, "operator()");
+ static_assert(sizeof(__PRETTY_FUNCTION__) == 51,
+ "auto main()::<anonymous class>::operator()() const");
+ }
+ }
+ ();
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D1491.2.patch
Type: text/x-patch
Size: 3114 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130823/05a7097e/attachment.bin>
More information about the cfe-commits
mailing list