1 //===--- APSIntType.cpp - Simple record of the type of APSInts ------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "clang/StaticAnalyzer/Core/PathSensitive/APSIntType.h"
12 using namespace clang;
15 APSIntType::RangeTestResultKind
16 APSIntType::testInRange(const llvm::APSInt &Value) const {
17 // Negative numbers cannot be losslessly converted to unsigned type.
18 if (IsUnsigned && Value.isSigned() && Value.isNegative())
21 // Signed integers can be converted to signed integers of the same width
22 // or (if positive) unsigned integers with one fewer bit.
23 // Unsigned integers can be converted to unsigned integers of the same width
24 // or signed integers with one more bit.
27 MinBits = Value.getMinSignedBits() - IsUnsigned;
29 MinBits = Value.getActiveBits() + !IsUnsigned;
31 if (MinBits <= BitWidth)
34 if (Value.isSigned() && Value.isNegative())