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

Eli Friedman eli.friedman at gmail.com
Tue Sep 21 18:44:21 PDT 2010


On Tue, Sep 21, 2010 at 3:53 PM, Fariborz Jahanian <fjahanian at apple.com> wrote:
> 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);
>   }


Why exactly does it matter if the subexpression is a null pointer constant?

-Eli




More information about the cfe-commits mailing list