summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
authorEli Friedman <eli.friedman@gmail.com>2009-02-20 01:15:07 +0000
committerEli Friedman <eli.friedman@gmail.com>2009-02-20 01:15:07 +0000
commit742421e2e7887ef018585e5fdbbad647a9dfca5b (patch)
tree1a094a4d1613c4a8e3a6b9908a5bba069df2c398 /clang
parentc86fb5ecb4e7327ca0dcd8570d0d93d08cf5d622 (diff)
downloadbcm5719-llvm-742421e2e7887ef018585e5fdbbad647a9dfca5b.tar.gz
bcm5719-llvm-742421e2e7887ef018585e5fdbbad647a9dfca5b.zip
ExprConstant handling for a couple more cases of pointer-to-int casts
from the testsuite. llvm-svn: 65098
Diffstat (limited to 'clang')
-rw-r--r--clang/lib/AST/ExprConstant.cpp21
1 files changed, 18 insertions, 3 deletions
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 5e08e52a7ca..fe442974383 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/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);
OpenPOWER on IntegriCloud