diff options
author | Daniel Dunbar <daniel@zuster.org> | 2009-02-19 22:24:01 +0000 |
---|---|---|
committer | Daniel Dunbar <daniel@zuster.org> | 2009-02-19 22:24:01 +0000 |
commit | 1c8560d93ef3ae8d4fded9d355b27d53f5b04e8c (patch) | |
tree | 6bc9fc5d425fd3896ec20668b220b42c57e836bb /clang/lib/AST/ExprConstant.cpp | |
parent | cf04aa1a024b8cbcf95593c06aaf62e8ce7ca6c0 (diff) | |
download | bcm5719-llvm-1c8560d93ef3ae8d4fded9d355b27d53f5b04e8c.tar.gz bcm5719-llvm-1c8560d93ef3ae8d4fded9d355b27d53f5b04e8c.zip |
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.
llvm-svn: 65074
Diffstat (limited to 'clang/lib/AST/ExprConstant.cpp')
-rw-r--r-- | clang/lib/AST/ExprConstant.cpp | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index cfe1a74f320..5e08e52a7ca 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/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()) |