aboutsummaryrefslogtreecommitdiff
path: root/lib/AST/ExprConstant.cpp
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2009-02-19 22:24:01 +0000
committerDaniel Dunbar <daniel@zuster.org>2009-02-19 22:24:01 +0000
commitdd2116462ae311043986ae8b7fba27e68c1b2e66 (patch)
tree59d458a936f5d0d54b12a14087aff5aa3d9a767d /lib/AST/ExprConstant.cpp
parentb92dac8bc2f6f73919825f9af693a8a7e89ae1d4 (diff)
Extend Evaluate() to fold (int) <pointer type>.
- PR3463, PR3398, <rdar://problem/6553401> crash on relocatable symbol addresses as constants in static locals. - There are many more scenarious we could handle (like arithmetic on such an int) but this is the main use case. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@65074 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AST/ExprConstant.cpp')
-rw-r--r--lib/AST/ExprConstant.cpp15
1 files changed, 11 insertions, 4 deletions
diff --git a/lib/AST/ExprConstant.cpp b/lib/AST/ExprConstant.cpp
index cfe1a74f32..5e08e52a7c 100644
--- a/lib/AST/ExprConstant.cpp
+++ b/lib/AST/ExprConstant.cpp
@@ -1057,7 +1057,7 @@ bool IntExprEvaluator::VisitCastExpr(CastExpr *E) {
if (!Result.isInt())
return false;
- return Success(HandleIntToIntCast(DestType, SrcType,
+ return Success(HandleIntToIntCast(DestType, SrcType,
Result.getInt(), Info.Ctx), E);
}
@@ -1067,10 +1067,17 @@ bool IntExprEvaluator::VisitCastExpr(CastExpr *E) {
if (!EvaluatePointer(SubExpr, LV, Info))
return false;
- if (LV.getLValueBase())
- return false;
+ if (LV.getLValueBase()) {
+ // Only allow based lvalue casts if they are lossless.
+ if (Info.Ctx.getTypeSize(DestType) != Info.Ctx.getTypeSize(SrcType))
+ return false;
+
+ Result = LV;
+ return true;
+ }
- return Success(LV.getLValueOffset(), E);
+ APSInt AsInt = Info.Ctx.MakeIntValue(LV.getLValueOffset(), SrcType);
+ return Success(HandleIntToIntCast(DestType, SrcType, AsInt, Info.Ctx), E);
}
if (!SrcType->isRealFloatingType())