]> granicus.if.org Git - clang/commitdiff
[VLA] Handle VLA size expression in a full-expression context.
authorTim Shen <timshen91@gmail.com>
Tue, 14 Feb 2017 23:46:37 +0000 (23:46 +0000)
committerTim Shen <timshen91@gmail.com>
Tue, 14 Feb 2017 23:46:37 +0000 (23:46 +0000)
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

lib/Sema/SemaTemplateInstantiateDecl.cpp
lib/Sema/TreeTransform.h
test/Sema/pr30306.cpp [new file with mode: 0644]

index a0e4d2999d9fe2317a94ac657b2b4f3b7d98eb95..f7db189de84912ff2e4b4cbab1c3a27fc3c2931f 100644 (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);
 
index ef349c395f8a2d49095eb1a57d3928d7e3f78ed8..8a63d3547464f20387f0926b55a61bfbed9a5a89 100644 (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();
 
diff --git a/test/Sema/pr30306.cpp b/test/Sema/pr30306.cpp
new file mode 100644 (file)
index 0000000..7442377
--- /dev/null
@@ -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>(); }