clang  10.0.0svn
APSIntType.cpp
Go to the documentation of this file.
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 
10 
11 using namespace clang;
12 using namespace ento;
13 
16  bool AllowSignConversions) const {
17 
18  // Negative numbers cannot be losslessly converted to unsigned type.
19  if (IsUnsigned && !AllowSignConversions &&
20  Value.isSigned() && Value.isNegative())
21  return RTR_Below;
22 
23  unsigned MinBits;
24  if (AllowSignConversions) {
25  if (Value.isSigned() && !IsUnsigned)
26  MinBits = Value.getMinSignedBits();
27  else
28  MinBits = Value.getActiveBits();
29 
30  } 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  if (Value.isSigned())
36  MinBits = Value.getMinSignedBits() - IsUnsigned;
37  else
38  MinBits = Value.getActiveBits() + !IsUnsigned;
39  }
40 
41  if (MinBits <= BitWidth)
42  return RTR_Within;
43 
44  if (Value.isSigned() && Value.isNegative())
45  return RTR_Below;
46  else
47  return RTR_Above;
48 }
Value is less than the minimum representable value.
Definition: APSIntType.h:77
Value is representable using this type.
Definition: APSIntType.h:78
RangeTestResultKind testInRange(const llvm::APSInt &Val, bool AllowMixedSign) const LLVM_READONLY
Tests whether a given value is losslessly representable using this type.
Definition: APSIntType.cpp:15
llvm::APSInt APSInt
Value is greater than the maximum representable value.
Definition: APSIntType.h:79
RangeTestResultKind
Used to classify whether a value is representable using this type.
Definition: APSIntType.h:76
Dataflow Directional Tag Classes.