aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFariborz Jahanian <fjahanian@apple.com>2010-09-21 22:53:33 +0000
committerFariborz Jahanian <fjahanian@apple.com>2010-09-21 22:53:33 +0000
commitf4435703872acb6eb0ff01b52414584e08d9ee35 (patch)
treee90bfb5fdb60c0a1b28c646254f3422815505333
parent7ccc58f9ffa0d2cad6fcf00b66c0fc0d2fae26e6 (diff)
Fixes an IRgen ICE due to cast of null pointer to
a vla type (fixes pr7827). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@114495 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/CodeGen/CGExprScalar.cpp13
-rw-r--r--test/CodeGen/vla.c9
2 files changed, 20 insertions, 2 deletions
diff --git a/lib/CodeGen/CGExprScalar.cpp b/lib/CodeGen/CGExprScalar.cpp
index 73e94d1ece..055e3f7e67 100644
--- a/lib/CodeGen/CGExprScalar.cpp
+++ b/lib/CodeGen/CGExprScalar.cpp
@@ -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);
}
diff --git a/test/CodeGen/vla.c b/test/CodeGen/vla.c
index 17704727b0..8011497bf5 100644
--- a/test/CodeGen/vla.c
+++ b/test/CodeGen/vla.c
@@ -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);
+}
+