r258669 - Allow capture typedefs/type aliases for VLAs in lambdas/captured statements chain.
Alexey Bataev via cfe-commits
cfe-commits at lists.llvm.org
Sun Jan 24 23:06:23 PST 2016
Author: abataev
Date: Mon Jan 25 01:06:23 2016
New Revision: 258669
URL: http://llvm.org/viewvc/llvm-project?rev=258669&view=rev
Log:
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.
Modified:
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/test/CodeGenCXX/lambda-expressions.cpp
Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=258669&r1=258668&r2=258669&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Mon Jan 25 01:06:23 2016
@@ -3887,14 +3887,24 @@ Sema::CreateUnaryExprOrTypeTraitExpr(Typ
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);
+ }
}
}
}
Modified: cfe/trunk/test/CodeGenCXX/lambda-expressions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/lambda-expressions.cpp?rev=258669&r1=258668&r2=258669&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/lambda-expressions.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/lambda-expressions.cpp Mon Jan 25 01:06:23 2016
@@ -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);
+ }();
}();
}
More information about the cfe-commits
mailing list