From: Tim Shen Date: Tue, 14 Feb 2017 23:46:37 +0000 (+0000) Subject: [VLA] Handle VLA size expression in a full-expression context. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e41ecb53e272474f548b3db7793585aaa361ea64;p=clang [VLA] Handle VLA size expression in a full-expression context. Summary: Previously the cleanups (e.g. dtor calls) are inserted into the outer scope (e.g. function body scope), instead of it's own scope. After the fix, the cleanups are inserted right after getting the size value. This fixes pr30306. Reviewers: rsmith Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D24333 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@295123 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaTemplateInstantiateDecl.cpp b/lib/Sema/SemaTemplateInstantiateDecl.cpp index a0e4d2999d..f7db189de8 100644 --- a/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -3864,6 +3864,8 @@ void Sema::InstantiateFunctionDefinition(SourceLocation PointOfInstantiation, if (Body.isInvalid()) Function->setInvalidDecl(); + // FIXME: finishing the function body while in an expression evaluation + // context seems wrong. Investigate more. ActOnFinishFunctionBody(Function, Body.get(), /*IsInstantiation=*/true); diff --git a/lib/Sema/TreeTransform.h b/lib/Sema/TreeTransform.h index ef349c395f..8a63d35474 100644 --- a/lib/Sema/TreeTransform.h +++ b/lib/Sema/TreeTransform.h @@ -4603,8 +4603,15 @@ TreeTransform::TransformVariableArrayType(TypeLocBuilder &TLB, if (ElementType.isNull()) return QualType(); - ExprResult SizeResult - = getDerived().TransformExpr(T->getSizeExpr()); + ExprResult SizeResult; + { + EnterExpressionEvaluationContext Context(SemaRef, + Sema::PotentiallyEvaluated); + SizeResult = getDerived().TransformExpr(T->getSizeExpr()); + } + if (SizeResult.isInvalid()) + return QualType(); + SizeResult = SemaRef.ActOnFinishFullExpr(SizeResult.get()); if (SizeResult.isInvalid()) return QualType(); diff --git a/test/Sema/pr30306.cpp b/test/Sema/pr30306.cpp new file mode 100644 index 0000000000..7442377dc5 --- /dev/null +++ b/test/Sema/pr30306.cpp @@ -0,0 +1,15 @@ +// RUN: %clang_cc1 -x c++ -emit-llvm < %s | FileCheck %s + +struct A { A(int); ~A(); }; +int f(const A &); +// CHECK: call void @_ZN1AC1Ei +// CHECK-NEXT: call i32 @_Z1fRK1A +// CHECK-NEXT: call void @_ZN1AD1Ev +// CHECK: call void @_ZN1AC1Ei +// CHECK-NEXT: call i32 @_Z1fRK1A +// CHECK-NEXT: call void @_ZN1AD1Ev +template void g() { + int a[f(3)]; + int b[f(3)]; +} +int main() { g(); }