]> granicus.if.org Git - clang/commitdiff
Allow capture typedefs/type aliases for VLAs in lambdas/captured statements chain.
authorAlexey Bataev <a.bataev@hotmail.com>
Mon, 25 Jan 2016 07:06:23 +0000 (07:06 +0000)
committerAlexey Bataev <a.bataev@hotmail.com>
Mon, 25 Jan 2016 07:06:23 +0000 (07:06 +0000)
Previous it was allowed to capture VLAs/types with arrays of runtime bounds only inside the first lambda/capture statement in stack. Patch allows to capture these typedefs implicitly in chains of lambdas/captured statements.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@258669 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaExpr.cpp
test/CodeGenCXX/lambda-expressions.cpp

index fc1a9268b163e8667188327bde680f6f70f4cf0b..b7d494fa5cbb6e89538799e2dfa15884e2666838 100644 (file)
@@ -3887,14 +3887,24 @@ Sema::CreateUnaryExprOrTypeTraitExpr(TypeSourceInfo *TInfo,
 
   if (T->isVariablyModifiedType() && FunctionScopes.size() > 1) {
     if (auto *TT = T->getAs<TypedefType>()) {
-      if (auto *CSI = dyn_cast<CapturingScopeInfo>(FunctionScopes.back())) {
+      for (auto I = FunctionScopes.rbegin(),
+                E = std::prev(FunctionScopes.rend());
+           I != E; ++I) {
+        auto *CSI = dyn_cast<CapturingScopeInfo>(*I);
+        if (CSI == nullptr)
+          break;
         DeclContext *DC = nullptr;
-        if (auto LSI = dyn_cast<LambdaScopeInfo>(CSI))
+        if (auto *LSI = dyn_cast<LambdaScopeInfo>(CSI))
           DC = LSI->CallOperator;
-        else if (auto CRSI = dyn_cast<CapturedRegionScopeInfo>(CSI))
+        else if (auto *CRSI = dyn_cast<CapturedRegionScopeInfo>(CSI))
           DC = CRSI->TheCapturedDecl;
-        if (DC && TT->getDecl()->getDeclContext() != DC)
+        else if (auto *BSI = dyn_cast<BlockScopeInfo>(CSI))
+          DC = BSI->TheDecl;
+        if (DC) {
+          if (DC->containsDecl(TT->getDecl()))
+            break;
           captureVariablyModifiedType(Context, T, CSI);
+        }
       }
     }
   }
index 4df44f4c5f7f8b0b49a0f90ae09fd0b9205fe012..f59d360314e4b73b4aa5a21c2421d8a38692420d 100644 (file)
@@ -12,12 +12,16 @@ extern "C" auto cvar = []{};
 
 // CHECK-LABEL: define i32 @_Z9ARBSizeOfi(i32
 int ARBSizeOf(int n) {
-  typedef double (T)[8][n];
-  using TT = double [8][n];
+  typedef double(T)[8][n];
+  using TT = double[8][n];
   return [&]() -> int {
     typedef double(T1)[8][n];
     using TT1 = double[8][n];
-    return sizeof(T) + sizeof(T1) + sizeof(TT) + sizeof(TT1);
+    return [&n]() -> int {
+      typedef double(T2)[8][n];
+      using TT2 = double[8][n];
+      return sizeof(T) + sizeof(T1) + sizeof(T2) + sizeof(TT) + sizeof(TT1) + sizeof(TT2);
+    }();
   }();
 }