[PATCH] D24333: [VLA] Handle VLA size expression in a full-expression context.

Tim Shen via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Feb 14 15:58:26 PST 2017


This revision was automatically updated to reflect the committed changes.
Closed by commit rL295123: [VLA] Handle VLA size expression in a full-expression context. (authored by timshen).

Changed prior to commit:
  https://reviews.llvm.org/D24333?vs=86377&id=88464#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D24333

Files:
  cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
  cfe/trunk/lib/Sema/TreeTransform.h
  cfe/trunk/test/Sema/pr30306.cpp


Index: cfe/trunk/test/Sema/pr30306.cpp
===================================================================
--- cfe/trunk/test/Sema/pr30306.cpp
+++ cfe/trunk/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<typename T> void g() {
+  int a[f(3)];
+  int b[f(3)];
+}
+int main() { g<int>(); }
Index: cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
===================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -3864,6 +3864,8 @@
     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: cfe/trunk/lib/Sema/TreeTransform.h
===================================================================
--- cfe/trunk/lib/Sema/TreeTransform.h
+++ cfe/trunk/lib/Sema/TreeTransform.h
@@ -4603,8 +4603,15 @@
   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();
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D24333.88464.patch
Type: text/x-patch
Size: 1910 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170214/157a5a50/attachment-0001.bin>


More information about the cfe-commits mailing list