/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/StaticAnalyzer/Core/APSIntType.cpp
Line | Count | Source |
1 | | //===--- APSIntType.cpp - Simple record of the type of APSInts ------------===// |
2 | | // |
3 | | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | | // See https://llvm.org/LICENSE.txt for license information. |
5 | | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | | // |
7 | | //===----------------------------------------------------------------------===// |
8 | | |
9 | | #include "clang/StaticAnalyzer/Core/PathSensitive/APSIntType.h" |
10 | | |
11 | | using namespace clang; |
12 | | using namespace ento; |
13 | | |
14 | | APSIntType::RangeTestResultKind |
15 | | APSIntType::testInRange(const llvm::APSInt &Value, |
16 | 1.12M | bool AllowSignConversions) const { |
17 | | |
18 | | // Negative numbers cannot be losslessly converted to unsigned type. |
19 | 1.12M | if (IsUnsigned && !AllowSignConversions447k && |
20 | 1.12M | Value.isSigned()910 && Value.isNegative()34 ) |
21 | 14 | return RTR_Below; |
22 | | |
23 | 1.12M | unsigned MinBits; |
24 | 1.12M | if (AllowSignConversions) { |
25 | 973k | if (Value.isSigned() && !IsUnsigned527k ) |
26 | 525k | MinBits = Value.getSignificantBits(); |
27 | 447k | else |
28 | 447k | MinBits = Value.getActiveBits(); |
29 | | |
30 | 973k | } else { |
31 | | // Signed integers can be converted to signed integers of the same width |
32 | | // or (if positive) unsigned integers with one fewer bit. |
33 | | // Unsigned integers can be converted to unsigned integers of the same width |
34 | | // or signed integers with one more bit. |
35 | 149k | if (Value.isSigned()) |
36 | 148k | MinBits = Value.getSignificantBits() - IsUnsigned; |
37 | 932 | else |
38 | 932 | MinBits = Value.getActiveBits() + !IsUnsigned; |
39 | 149k | } |
40 | | |
41 | 1.12M | if (MinBits <= BitWidth) |
42 | 1.12M | return RTR_Within; |
43 | | |
44 | 223 | if (Value.isSigned() && Value.isNegative()188 ) |
45 | 117 | return RTR_Below; |
46 | 106 | else |
47 | 106 | return RTR_Above; |
48 | 223 | } |