diff options
author | Eli Friedman <eli.friedman@gmail.com> | 2009-02-20 01:15:07 +0000 |
---|---|---|
committer | Eli Friedman <eli.friedman@gmail.com> | 2009-02-20 01:15:07 +0000 |
commit | be26570e3faa009bdcefedfaf04473e518940520 (patch) | |
tree | e45980ca5f6ac30d9cb00f65822ac2f29770c66b /lib/AST/ExprConstant.cpp | |
parent | 4f54526a31458c19aad19e5d3fb4ba2a5275ecb6 (diff) |
ExprConstant handling for a couple more cases of pointer-to-int casts
from the testsuite.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@65098 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AST/ExprConstant.cpp')
-rw-r--r-- | lib/AST/ExprConstant.cpp | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/lib/AST/ExprConstant.cpp b/lib/AST/ExprConstant.cpp index 5e08e52a7c..fe44297438 100644 --- a/lib/AST/ExprConstant.cpp +++ b/lib/AST/ExprConstant.cpp @@ -1053,9 +1053,10 @@ bool IntExprEvaluator::VisitCastExpr(CastExpr *E) { if (!Visit(SubExpr)) return false; - // FIXME: Support cast on LValue results. - if (!Result.isInt()) - return false; + if (!Result.isInt()) { + // Only allow casts of lvalues if they are lossless. + return Info.Ctx.getTypeSize(DestType) == Info.Ctx.getTypeSize(SrcType); + } return Success(HandleIntToIntCast(DestType, SrcType, Result.getInt(), Info.Ctx), E); @@ -1080,6 +1081,20 @@ bool IntExprEvaluator::VisitCastExpr(CastExpr *E) { return Success(HandleIntToIntCast(DestType, SrcType, AsInt, Info.Ctx), E); } + if (SrcType->isArrayType() || SrcType->isFunctionType()) { + // This handles double-conversion cases, where there's both + // an l-value promotion and an implicit conversion to int. + APValue LV; + if (!EvaluateLValue(SubExpr, LV, Info)) + return false; + + if (Info.Ctx.getTypeSize(DestType) != Info.Ctx.getTypeSize(Info.Ctx.VoidPtrTy)) + return false; + + Result = LV; + return true; + } + if (!SrcType->isRealFloatingType()) return Error(E->getExprLoc(), diag::note_invalid_subexpr_in_ice, E); |