diff options
author | rdivacky <rdivacky@FreeBSD.org> | 2010-03-21 10:50:08 +0000 |
---|---|---|
committer | rdivacky <rdivacky@FreeBSD.org> | 2010-03-21 10:50:08 +0000 |
commit | 1e255aab650a7fa2047fd953cae65b12215280af (patch) | |
tree | 508d4388db78f87d35bf26a0400b4b03bc4c1f13 /lib/AST/ExprConstant.cpp | |
parent | 1033b7c1e32962948b01a25145829f17bc70a8de (diff) | |
download | FreeBSD-src-1e255aab650a7fa2047fd953cae65b12215280af.zip FreeBSD-src-1e255aab650a7fa2047fd953cae65b12215280af.tar.gz |
Update clang to r99115.
Diffstat (limited to 'lib/AST/ExprConstant.cpp')
-rw-r--r-- | lib/AST/ExprConstant.cpp | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/lib/AST/ExprConstant.cpp b/lib/AST/ExprConstant.cpp index e036692..eeeeb5c 100644 --- a/lib/AST/ExprConstant.cpp +++ b/lib/AST/ExprConstant.cpp @@ -406,27 +406,34 @@ APValue PointerExprEvaluator::VisitBinaryOperator(const BinaryOperator *E) { if (!EvaluatePointer(PExp, ResultLValue, Info)) return APValue(); - llvm::APSInt AdditionalOffset(32); + llvm::APSInt AdditionalOffset; if (!EvaluateInteger(IExp, AdditionalOffset, Info)) return APValue(); - QualType PointeeType = PExp->getType()->getAs<PointerType>()->getPointeeType(); - CharUnits SizeOfPointee; + // Compute the new offset in the appropriate width. + + QualType PointeeType = + PExp->getType()->getAs<PointerType>()->getPointeeType(); + llvm::APSInt SizeOfPointee(AdditionalOffset); // Explicitly handle GNU void* and function pointer arithmetic extensions. if (PointeeType->isVoidType() || PointeeType->isFunctionType()) - SizeOfPointee = CharUnits::One(); + SizeOfPointee = 1; else - SizeOfPointee = Info.Ctx.getTypeSizeInChars(PointeeType); - - CharUnits Offset = ResultLValue.getLValueOffset(); + SizeOfPointee = Info.Ctx.getTypeSizeInChars(PointeeType).getQuantity(); + llvm::APSInt Offset(AdditionalOffset); + Offset = ResultLValue.getLValueOffset().getQuantity(); if (E->getOpcode() == BinaryOperator::Add) - Offset += AdditionalOffset.getLimitedValue() * SizeOfPointee; + Offset += AdditionalOffset * SizeOfPointee; else - Offset -= AdditionalOffset.getLimitedValue() * SizeOfPointee; + Offset -= AdditionalOffset * SizeOfPointee; - return APValue(ResultLValue.getLValueBase(), Offset); + // Sign extend prior to converting back to a char unit. + if (Offset.getBitWidth() < 64) + Offset.extend(64); + return APValue(ResultLValue.getLValueBase(), + CharUnits::fromQuantity(Offset.getLimitedValue())); } APValue PointerExprEvaluator::VisitUnaryAddrOf(const UnaryOperator *E) { |