diff options
author | Daniel Dunbar <daniel@zuster.org> | 2009-02-20 18:22:23 +0000 |
---|---|---|
committer | Daniel Dunbar <daniel@zuster.org> | 2009-02-20 18:22:23 +0000 |
commit | 69ab26a8623141f35e86817cfc6e0fbe7639a40f (patch) | |
tree | f7298cff89a7d46e4904bf3041ee7929a9af2665 /lib/AST/ExprConstant.cpp | |
parent | cafeb35117578585dbbfef0bc79d8aa27712bc0e (diff) |
Handle constant int -> ptr casts of lvalue results.
- PR3463 (again).
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@65133 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AST/ExprConstant.cpp')
-rw-r--r-- | lib/AST/ExprConstant.cpp | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/lib/AST/ExprConstant.cpp b/lib/AST/ExprConstant.cpp index 0fcbdf12f0..64d3fdd8a7 100644 --- a/lib/AST/ExprConstant.cpp +++ b/lib/AST/ExprConstant.cpp @@ -54,6 +54,7 @@ struct EvalInfo { static bool EvaluateLValue(const Expr *E, APValue &Result, EvalInfo &Info); static bool EvaluatePointer(const Expr *E, APValue &Result, EvalInfo &Info); static bool EvaluateInteger(const Expr *E, APSInt &Result, EvalInfo &Info); +static bool EvaluateIntegerOrLValue(const Expr *E, APValue &Result, EvalInfo &Info); static bool EvaluateFloat(const Expr *E, APFloat &Result, EvalInfo &Info); static bool EvaluateComplex(const Expr *E, APValue &Result, EvalInfo &Info); @@ -351,11 +352,17 @@ APValue PointerExprEvaluator::VisitCastExpr(const CastExpr* E) { } if (SubExpr->getType()->isIntegralType()) { - llvm::APSInt Result(32); - if (EvaluateInteger(SubExpr, Result, Info)) { - Result.extOrTrunc((unsigned)Info.Ctx.getTypeSize(E->getType())); - return APValue(0, Result.getZExtValue()); + APValue Result; + if (!EvaluateIntegerOrLValue(SubExpr, Result, Info)) + return APValue(); + + if (Result.isInt()) { + Result.getInt().extOrTrunc((unsigned)Info.Ctx.getTypeSize(E->getType())); + return APValue(0, Result.getInt().getZExtValue()); } + + // Cast is of an lvalue, no need to change value. + return Result; } if (SubExpr->getType()->isFunctionType() || @@ -587,15 +594,17 @@ private: }; } // end anonymous namespace -static bool EvaluateInteger(const Expr* E, APSInt &Result, EvalInfo &Info) { +static bool EvaluateIntegerOrLValue(const Expr* E, APValue &Result, EvalInfo &Info) { if (!E->getType()->isIntegralType()) return false; + return IntExprEvaluator(Info, Result).Visit(const_cast<Expr*>(E)); +} + +static bool EvaluateInteger(const Expr* E, APSInt &Result, EvalInfo &Info) { APValue Val; - if (!IntExprEvaluator(Info, Val).Visit(const_cast<Expr*>(E)) || - !Val.isInt()) + if (!EvaluateIntegerOrLValue(E, Val, Info) || !Val.isInt()) return false; - Result = Val.getInt(); return true; } |