[cfe-commits] r114495 - in /cfe/trunk: lib/CodeGen/CGExprScalar.cpp test/CodeGen/vla.c

Fariborz Jahanian fjahanian at apple.com
Tue Sep 21 15:53:33 PDT 2010


Author: fjahanian
Date: Tue Sep 21 17:53:33 2010
New Revision: 114495

URL: http://llvm.org/viewvc/llvm-project?rev=114495&view=rev
Log:
Fixes an IRgen ICE due to cast of null pointer to
a vla type (fixes pr7827).

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

Modified: cfe/trunk/lib/CodeGen/CGExprScalar.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprScalar.cpp?rev=114495&r1=114494&r2=114495&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprScalar.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprScalar.cpp Tue Sep 21 17:53:33 2010
@@ -209,8 +209,17 @@
   }
   Value *VisitCastExpr(CastExpr *E) {
     // Make sure to evaluate VLA bounds now so that we have them for later.
-    if (E->getType()->isVariablyModifiedType())
-      CGF.EmitVLASize(E->getType());
+    if (E->getType()->isVariablyModifiedType()) {
+      // Implicit cast of a null pointer to a vla type need not result in vla
+      // size computation which is not always possible in any case (see pr7827).
+      bool NeedSize = true;
+      if (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E))
+        NeedSize = 
+          !ICE->getSubExpr()->isNullPointerConstant(CGF.getContext(),
+                                                Expr::NPC_ValueDependentIsNull);
+      if (NeedSize)
+        CGF.EmitVLASize(E->getType());
+    }
 
     return EmitCastExpr(E);
   }

Modified: cfe/trunk/test/CodeGen/vla.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/vla.c?rev=114495&r1=114494&r2=114495&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/vla.c (original)
+++ cfe/trunk/test/CodeGen/vla.c Tue Sep 21 17:53:33 2010
@@ -50,3 +50,12 @@
   }
   // CHECK: call void @llvm.stackrestore(i8*
 }
+
+// pr7827
+void function(short width, int data[][width]) {}
+
+void test() {
+     // CHECK: call void @function(i16 signext 1, i32* null)
+     function(1, 0);
+}
+





More information about the cfe-commits mailing list