Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/clang/lib/StaticAnalyzer/Core/APSIntType.cpp
Line
Count
Source (jump to first uncovered line)
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
607k
                        bool AllowSignConversions) const {
17
607k
18
607k
  // Negative numbers cannot be losslessly converted to unsigned type.
19
607k
  if (IsUnsigned && 
!AllowSignConversions337k
&&
20
607k
      
Value.isSigned()0
&&
Value.isNegative()0
)
21
0
    return RTR_Below;
22
607k
23
607k
  unsigned MinBits;
24
607k
  if (AllowSignConversions) {
25
607k
    if (Value.isSigned() && 
!IsUnsigned270k
)
26
269k
      MinBits = Value.getMinSignedBits();
27
337k
    else
28
337k
      MinBits = Value.getActiveBits();
29
607k
30
607k
  } else {
31
0
    // Signed integers can be converted to signed integers of the same width
32
0
    // or (if positive) unsigned integers with one fewer bit.
33
0
    // Unsigned integers can be converted to unsigned integers of the same width
34
0
    // or signed integers with one more bit.
35
0
    if (Value.isSigned())
36
0
      MinBits = Value.getMinSignedBits() - IsUnsigned;
37
0
    else
38
0
      MinBits = Value.getActiveBits() + !IsUnsigned;
39
0
  }
40
607k
41
607k
  if (MinBits <= BitWidth)
42
607k
    return RTR_Within;
43
118
44
118
  if (Value.isSigned() && 
Value.isNegative()116
)
45
80
    return RTR_Below;
46
38
  else
47
38
    return RTR_Above;
48
118
}