[PATCH] Handle captured statements for predefined expressions

Wei Pan wei.pan at intel.com
Fri Aug 23 11:47:04 PDT 2013


wwwwpan added you to the CC list for the revision "Handle captured statements for predefined expressions".

Hi bkramer,

- this fixes crashes when a captured statement has an assertion.

This follows blocks and seemly we need to fix its handling too. Not quite sure the intent behind. Please let me know if there is a better fix. I would be happy to fix it in a proper way.

-- forgot to cc cfe-commits

http://llvm-reviews.chandlerc.com/D1491

Files:
  lib/CodeGen/CGExpr.cpp
  lib/Sema/SemaExpr.cpp
  test/SemaCXX/predefined-expr.cpp

Index: lib/CodeGen/CGExpr.cpp
===================================================================
--- lib/CodeGen/CGExpr.cpp
+++ lib/CodeGen/CGExpr.cpp
@@ -1968,9 +1968,9 @@
 
     const Type *ElemType = E->getType()->getArrayElementTypeNoTypeQual();
     std::string FunctionName;
-    if (isa<BlockDecl>(CurDecl)) {
-      // Blocks use the mangled function name.
-      // FIXME: ComputeName should handle blocks.
+    if (isa<BlockDecl>(CurDecl) || isa<CapturedDecl>(CurDecl)) {
+      // Blocks and captured statements use the mangled function name.
+      // FIXME: ComputeName should handle blocks and captured statements.
       FunctionName = FnName.str();
     } else {
       FunctionName = PredefinedExpr::ComputeName(IdentType, CurDecl);
Index: lib/Sema/SemaExpr.cpp
===================================================================
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -2759,12 +2759,14 @@
   // Pre-defined identifiers are of type char[x], where x is the length of the
   // string.
 
-  // Pick the current block, lambda or function.
+  // Pick the current block, lambda, captured statement or function.
   Decl *currentDecl;
   if (const BlockScopeInfo *BSI = getCurBlock())
     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,11 @@
     static_assert(sizeof(__PRETTY_FUNCTION__) == 1, "__main_block_invoke");
   }
   ();
+
+  #pragma clang __debug captured
+  {
+    static_assert(sizeof(__func__) == 1, "__captured_stmt");
+    static_assert(sizeof(__FUNCTION__) == 1, "__captured_stmt");
+    static_assert(sizeof(__PRETTY_FUNCTION__) == 1, "__captured_stmt");
+  }
 }
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D1491.1.patch
Type: text/x-patch
Size: 2053 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130823/b2b1c404/attachment.bin>


More information about the cfe-commits mailing list