[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

llvm-svn: 295123
This commit is contained in:
Tim Shen 2017-02-14 23:46:37 +00:00
parent 222b30b9d3
commit b34d0ef2ca
3 changed files with 26 additions and 2 deletions

View File

@ -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);

View File

@ -4603,8 +4603,15 @@ TreeTransform<Derived>::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();

View File

@ -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<typename T> void g() {
int a[f(3)];
int b[f(3)];
}
int main() { g<int>(); }