From f4435703872acb6eb0ff01b52414584e08d9ee35 Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Tue, 21 Sep 2010 22:53:33 +0000 Subject: 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 --- lib/CodeGen/CGExprScalar.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'lib/CodeGen/CGExprScalar.cpp') 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(E)) + NeedSize = + !ICE->getSubExpr()->isNullPointerConstant(CGF.getContext(), + Expr::NPC_ValueDependentIsNull); + if (NeedSize) + CGF.EmitVLASize(E->getType()); + } return EmitCastExpr(E); } -- cgit v1.2.3