diff options
| author | Alexey Bataev <a.bataev@hotmail.com> | 2016-01-25 07:06:23 +0000 |
|---|---|---|
| committer | Alexey Bataev <a.bataev@hotmail.com> | 2016-01-25 07:06:23 +0000 |
| commit | 41ed6b7abaeb0ed5371c1fc3930fe4de1c7c6659 (patch) | |
| tree | c8291149bd23df63290b21d14506348fbe76166a /clang | |
| parent | 86a489e4f3b59aa4b638d149842f5a63883f1691 (diff) | |
| download | bcm5719-llvm-41ed6b7abaeb0ed5371c1fc3930fe4de1c7c6659.tar.gz bcm5719-llvm-41ed6b7abaeb0ed5371c1fc3930fe4de1c7c6659.zip | |
Allow capture typedefs/type aliases for VLAs in lambdas/captured statements chain.
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.
llvm-svn: 258669
Diffstat (limited to 'clang')
| -rw-r--r-- | clang/lib/Sema/SemaExpr.cpp | 18 | ||||
| -rw-r--r-- | clang/test/CodeGenCXX/lambda-expressions.cpp | 10 |
2 files changed, 21 insertions, 7 deletions
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index fc1a9268b16..b7d494fa5cb 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -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); + } } } } diff --git a/clang/test/CodeGenCXX/lambda-expressions.cpp b/clang/test/CodeGenCXX/lambda-expressions.cpp index 4df44f4c5f7..f59d360314e 100644 --- a/clang/test/CodeGenCXX/lambda-expressions.cpp +++ b/clang/test/CodeGenCXX/lambda-expressions.cpp @@ -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); + }(); }(); } |

