]> granicus.if.org Git - clang/commitdiff
Fixes an IRgen ICE due to cast of null pointer to
authorFariborz Jahanian <fjahanian@apple.com>
Tue, 21 Sep 2010 22:53:33 +0000 (22:53 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Tue, 21 Sep 2010 22:53:33 +0000 (22:53 +0000)
a vla type (fixes pr7827).

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@114495 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGExprScalar.cpp
test/CodeGen/vla.c

index 73e94d1ece11ddcc723a86774631b01b284acc12..055e3f7e679429502b2304bf7ca5586a733ab5cb 100644 (file)
@@ -209,8 +209,17 @@ public:
   }
   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);
   }
index 17704727b027319497abffc7b336c2619fd0c9f9..8011497bf57d56a94aadcba0b3c72a96367d06e4 100644 (file)
@@ -50,3 +50,12 @@ void f_8403108(unsigned x) {
   }
   // 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);
+}
+