Deleted Added
full compact
APSIntType.cpp (239462) APSIntType.cpp (249423)
1//===--- APSIntType.cpp - Simple record of the type of APSInts ------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "clang/StaticAnalyzer/Core/PathSensitive/APSIntType.h"
11
12using namespace clang;
13using namespace ento;
14
15APSIntType::RangeTestResultKind
1//===--- APSIntType.cpp - Simple record of the type of APSInts ------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "clang/StaticAnalyzer/Core/PathSensitive/APSIntType.h"
11
12using namespace clang;
13using namespace ento;
14
15APSIntType::RangeTestResultKind
16APSIntType::testInRange(const llvm::APSInt &Value) const {
16APSIntType::testInRange(const llvm::APSInt &Value,
17 bool AllowSignConversions) const {
18
17 // Negative numbers cannot be losslessly converted to unsigned type.
19 // Negative numbers cannot be losslessly converted to unsigned type.
18 if (IsUnsigned && Value.isSigned() && Value.isNegative())
20 if (IsUnsigned && !AllowSignConversions &&
21 Value.isSigned() && Value.isNegative())
19 return RTR_Below;
20
22 return RTR_Below;
23
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.
25 unsigned MinBits;
24 unsigned MinBits;
26 if (Value.isSigned())
27 MinBits = Value.getMinSignedBits() - IsUnsigned;
28 else
29 MinBits = Value.getActiveBits() + !IsUnsigned;
25 if (AllowSignConversions) {
26 if (Value.isSigned() && !IsUnsigned)
27 MinBits = Value.getMinSignedBits();
28 else
29 MinBits = Value.getActiveBits();
30
30
31 } else {
32 // Signed integers can be converted to signed integers of the same width
33 // or (if positive) unsigned integers with one fewer bit.
34 // Unsigned integers can be converted to unsigned integers of the same width
35 // or signed integers with one more bit.
36 if (Value.isSigned())
37 MinBits = Value.getMinSignedBits() - IsUnsigned;
38 else
39 MinBits = Value.getActiveBits() + !IsUnsigned;
40 }
41
31 if (MinBits <= BitWidth)
32 return RTR_Within;
33
34 if (Value.isSigned() && Value.isNegative())
35 return RTR_Below;
36 else
37 return RTR_Above;
38}
42 if (MinBits <= BitWidth)
43 return RTR_Within;
44
45 if (Value.isSigned() && Value.isNegative())
46 return RTR_Below;
47 else
48 return RTR_Above;
49}