summaryrefslogtreecommitdiffstats
path: root/clang
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
commit521c72c756be8f8b8e13d88cb651bd9fe200202f (patch)
tree4420277695df27b442111be0c7aba21aa16f7ad9 /clang
parent61158f98ab50402652d81c4fdb80631751913793 (diff)
downloadbcm5719-llvm-521c72c756be8f8b8e13d88cb651bd9fe200202f.tar.gz
bcm5719-llvm-521c72c756be8f8b8e13d88cb651bd9fe200202f.zip
Fixes an IRgen ICE due to cast of null pointer to
a vla type (fixes pr7827). llvm-svn: 114495
Diffstat (limited to 'clang')
-rw-r--r--clang/lib/CodeGen/CGExprScalar.cpp13
-rw-r--r--clang/test/CodeGen/vla.c9
2 files changed, 20 insertions, 2 deletions
diff --git a/clang/lib/CodeGen/CGExprScalar.cpp b/clang/lib/CodeGen/CGExprScalar.cpp
index 73e94d1ece1..055e3f7e679 100644
--- a/clang/lib/CodeGen/CGExprScalar.cpp
+++ b/clang/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/clang/test/CodeGen/vla.c b/clang/test/CodeGen/vla.c
index 17704727b02..8011497bf57 100644
--- a/clang/test/CodeGen/vla.c
+++ b/clang/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);
+}
+
OpenPOWER on IntegriCloud