r206223 - Ensure we evaluate VLA bounds if a variably-modified type is used as the

Richard Smith richard-llvm at metafoo.co.uk
Mon Apr 14 16:47:48 PDT 2014


Author: rsmith
Date: Mon Apr 14 18:47:48 2014
New Revision: 206223

URL: http://llvm.org/viewvc/llvm-project?rev=206223&view=rev
Log:
Ensure we evaluate VLA bounds if a variably-modified type is used as the
argument to __builtin_va_arg. Patch by Rahul Jain, some test massaging and
IR emission order changes by me.

Modified:
    cfe/trunk/lib/CodeGen/CGExprScalar.cpp
    cfe/trunk/test/CodeGen/varargs.c

Modified: cfe/trunk/lib/CodeGen/CGExprScalar.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprScalar.cpp?rev=206223&r1=206222&r2=206223&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprScalar.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprScalar.cpp Mon Apr 14 18:47:48 2014
@@ -3199,6 +3199,10 @@ Value *ScalarExprEmitter::VisitChooseExp
 }
 
 Value *ScalarExprEmitter::VisitVAArgExpr(VAArgExpr *VE) {
+  QualType Ty = VE->getType();
+  if (Ty->isVariablyModifiedType())
+    CGF.EmitVariablyModifiedType(Ty);
+
   llvm::Value *ArgValue = CGF.EmitVAListRef(VE->getSubExpr());
   llvm::Value *ArgPtr = CGF.EmitVAArg(ArgValue, VE->getType());
 

Modified: cfe/trunk/test/CodeGen/varargs.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/varargs.c?rev=206223&r1=206222&r2=206223&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/varargs.c (original)
+++ cfe/trunk/test/CodeGen/varargs.c Mon Apr 14 18:47:48 2014
@@ -1,5 +1,4 @@
-// RUN: %clang_cc1 -emit-llvm -o - %s | FileCheck %s
-
+// RUN: %clang_cc1 -triple i386-unknown-unknown -emit-llvm -o - %s | FileCheck %s
 
 // PR6433 - Don't crash on va_arg(typedef).
 typedef double gdouble;
@@ -15,3 +14,10 @@ void function_as_vararg() {
   // CHECK-NOT: llvm.trap
   vararg(0, focus_changed_cb);
 }
+
+void vla(int n, ...)
+{
+  __builtin_va_list ap;
+  void *p;
+  p = __builtin_va_arg(ap, typeof (int (*)[++n])); // CHECK: add nsw i32 {{.*}}, 1
+}





More information about the cfe-commits mailing list