From f5019451b3e9236c35c495c2792f314246e46e36 Mon Sep 17 00:00:00 2001 From: Alexey Bataev Date: Fri, 21 Jun 2019 17:28:41 +0000 Subject: [OPENMP]Fix PR42068: Vla type is not captured. If the variably modified type is declared outside of the captured region and then used in the cast expression along with array subscript expression, the type is not captured and it leads to the compiler crash. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@364080 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaExpr.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'lib/Sema/SemaExpr.cpp') diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 9b09059c15..8fd7e5eafa 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -4737,6 +4737,33 @@ Sema::CreateBuiltinArraySubscriptExpr(Expr *Base, SourceLocation LLoc, assert(VK == VK_RValue || LangOpts.CPlusPlus || !ResultType.isCForbiddenLValueType()); + if (LHSExp->IgnoreParenImpCasts()->getType()->isVariablyModifiedType() && + FunctionScopes.size() > 1) { + if (auto *TT = + LHSExp->IgnoreParenImpCasts()->getType()->getAs()) { + for (auto I = FunctionScopes.rbegin(), + E = std::prev(FunctionScopes.rend()); + I != E; ++I) { + auto *CSI = dyn_cast(*I); + if (CSI == nullptr) + break; + DeclContext *DC = nullptr; + if (auto *LSI = dyn_cast(CSI)) + DC = LSI->CallOperator; + else if (auto *CRSI = dyn_cast(CSI)) + DC = CRSI->TheCapturedDecl; + else if (auto *BSI = dyn_cast(CSI)) + DC = BSI->TheDecl; + if (DC) { + if (DC->containsDecl(TT->getDecl())) + break; + captureVariablyModifiedType( + Context, LHSExp->IgnoreParenImpCasts()->getType(), CSI); + } + } + } + } + return new (Context) ArraySubscriptExpr(LHSExp, RHSExp, ResultType, VK, OK, RLoc); } -- cgit v1.2.1