reference, declaration → definition definition → references, declarations, derived classes, virtual overrides reference to multiple definitions → definitions unreferenced |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | //===--- APSIntType.cpp - Simple record of the type of APSInts ------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// #include "clang/StaticAnalyzer/Core/PathSensitive/APSIntType.h" using namespace clang; using namespace ento; APSIntType::RangeTestResultKind APSIntType::testInRange(const llvm::APSInt &Value, bool AllowSignConversions) const { // Negative numbers cannot be losslessly converted to unsigned type. if (IsUnsigned && !AllowSignConversions && Value.isSigned() && Value.isNegative()) return RTR_Below; unsigned MinBits; if (AllowSignConversions) { if (Value.isSigned() && !IsUnsigned) MinBits = Value.getMinSignedBits(); else MinBits = Value.getActiveBits(); } else { // Signed integers can be converted to signed integers of the same width // or (if positive) unsigned integers with one fewer bit. // Unsigned integers can be converted to unsigned integers of the same width // or signed integers with one more bit. if (Value.isSigned()) MinBits = Value.getMinSignedBits() - IsUnsigned; else MinBits = Value.getActiveBits() + !IsUnsigned; } if (MinBits <= BitWidth) return RTR_Within; if (Value.isSigned() && Value.isNegative()) return RTR_Below; else return RTR_Above; } |