clang 20.0.0git
Public Member Functions | List of all members
clang::ento::RangeSet::Factory Class Reference

#include "clang/StaticAnalyzer/Core/PathSensitive/RangedConstraintManager.h"

Public Member Functions

 Factory (BasicValueFactory &BV)
 
RangeSet add (RangeSet LHS, RangeSet RHS)
 Create a new set with all ranges from both LHS and RHS.
 
RangeSet add (RangeSet Original, Range Element)
 Create a new set with all ranges from the original set plus the new one.
 
RangeSet add (RangeSet Original, const llvm::APSInt &Point)
 Create a new set with all ranges from the original set plus the point.
 
RangeSet unite (RangeSet LHS, RangeSet RHS)
 Create a new set which is a union of two given ranges.
 
RangeSet unite (RangeSet Original, Range Element)
 Create a new set by uniting given range set with the given range.
 
RangeSet unite (RangeSet Original, llvm::APSInt Point)
 Create a new set by uniting given range set with the given point.
 
RangeSet unite (RangeSet Original, llvm::APSInt From, llvm::APSInt To)
 Create a new set by uniting given range set with the given range between points.
 
RangeSet getEmptySet ()
 
RangeSet intersect (RangeSet LHS, RangeSet RHS)
 Intersect the given range sets.
 
RangeSet intersect (RangeSet What, llvm::APSInt Lower, llvm::APSInt Upper)
 Intersect the given set with the closed range [Lower, Upper].
 
RangeSet intersect (RangeSet What, llvm::APSInt Point)
 Intersect the given range with the given point.
 
RangeSet deletePoint (RangeSet From, const llvm::APSInt &Point)
 Delete the given point from the range set.
 
RangeSet negate (RangeSet What)
 Negate the given range set.
 
RangeSet castTo (RangeSet What, APSIntType Ty)
 Performs promotions, truncations and conversions of the given set.
 
RangeSet castTo (RangeSet What, QualType T)
 
BasicValueFactorygetValueFactory () const
 Return associated value factory.
 
RangeSet getRangeSet (Range Origin)
 Create a new set with just one range.
 
RangeSet getRangeSet (const llvm::APSInt &From, const llvm::APSInt &To)
 
RangeSet getRangeSet (const llvm::APSInt &Origin)
 

Detailed Description

Definition at line 121 of file RangedConstraintManager.h.

Constructor & Destructor Documentation

◆ Factory()

clang::ento::RangeSet::Factory::Factory ( BasicValueFactory BV)
inline

Definition at line 123 of file RangedConstraintManager.h.

Member Function Documentation

◆ add() [1/3]

RangeSet RangeSet::Factory::add ( RangeSet  LHS,
RangeSet  RHS 
)

Create a new set with all ranges from both LHS and RHS.

Possible intersections are not checked here.

Complexity: O(N + M) where N = size(LHS), M = size(RHS)

Definition at line 114 of file RangeConstraintManager.cpp.

References clang::ento::RangeSet::begin(), clang::ento::RangeSet::end(), clang::Result, and clang::ento::RangeSet::size().

◆ add() [2/3]

RangeSet RangeSet::Factory::add ( RangeSet  Original,
const llvm::APSInt &  Point 
)

Create a new set with all ranges from the original set plus the point.

Possible intersections are not checked here.

Complexity: O(N) where N = size(Original)

Definition at line 134 of file RangeConstraintManager.cpp.

◆ add() [3/3]

RangeSet RangeSet::Factory::add ( RangeSet  Original,
Range  Element 
)

Create a new set with all ranges from the original set plus the new one.

Possible intersections are not checked here.

Complexity: O(N) where N = size(Original)

Definition at line 122 of file RangeConstraintManager.cpp.

References clang::Result.

◆ castTo() [1/2]

RangeSet RangeSet::Factory::castTo ( RangeSet  What,
APSIntType  Ty 
)

Performs promotions, truncations and conversions of the given set.

This function is optimized for each of the six cast cases:

  • noop
  • conversion
  • truncation
  • truncation-conversion
  • promotion
  • promotion-conversion

NOTE: This function is NOT self-inverse for truncations, because of the higher bits loss:

  • castTo(castTo(OrigRangeOfInt, char), int) != OrigRangeOfInt.
  • castTo(castTo(OrigRangeOfChar, int), char) == OrigRangeOfChar. But it is self-inverse for all the rest casts.

Complexity:

  • Noop O(1);
  • Truncation O(N^2);
  • Another case O(N); where N = size(What)

Definition at line 676 of file RangeConstraintManager.cpp.

References clang::ento::RangeSet::getAPSIntType(), clang::ento::APSIntType::getBitWidth(), clang::ento::RangeSet::getBitWidth(), clang::ento::RangeSet::isEmpty(), clang::ento::APSIntType::isUnsigned(), and clang::ento::RangeSet::isUnsigned().

◆ castTo() [2/2]

RangeSet RangeSet::Factory::castTo ( RangeSet  What,
QualType  T 
)

◆ deletePoint()

RangeSet RangeSet::Factory::deletePoint ( RangeSet  From,
const llvm::APSInt &  Point 
)

Delete the given point from the range set.

Complexity: O(N) where N = size(From)

Definition at line 849 of file RangeConstraintManager.cpp.

References clang::ento::RangeSet::contains().

◆ getEmptySet()

RangeSet clang::ento::RangeSet::Factory::getEmptySet ( )
inline

Definition at line 168 of file RangedConstraintManager.h.

◆ getRangeSet() [1/3]

RangeSet clang::ento::RangeSet::Factory::getRangeSet ( const llvm::APSInt &  From,
const llvm::APSInt &  To 
)
inline

Definition at line 173 of file RangedConstraintManager.h.

References getRangeSet().

◆ getRangeSet() [2/3]

RangeSet clang::ento::RangeSet::Factory::getRangeSet ( const llvm::APSInt &  Origin)
inline

Definition at line 176 of file RangedConstraintManager.h.

References getRangeSet().

◆ getRangeSet() [3/3]

RangeSet RangeSet::Factory::getRangeSet ( Range  Origin)

Create a new set with just one range.

Definition at line 318 of file RangeConstraintManager.cpp.

References clang::Result.

Referenced by getRangeSet().

◆ getValueFactory()

BasicValueFactory & clang::ento::RangeSet::Factory::getValueFactory ( ) const
inline

Return associated value factory.

Definition at line 265 of file RangedConstraintManager.h.

◆ intersect() [1/3]

RangeSet RangeSet::Factory::intersect ( RangeSet  LHS,
RangeSet  RHS 
)

Intersect the given range sets.

Complexity: O(N + M) where N = size(LHS), M = size(RHS)

Definition at line 595 of file RangeConstraintManager.cpp.

References clang::ento::RangeSet::getMaxValue(), clang::ento::RangeSet::getMinValue(), and clang::ento::RangeSet::isEmpty().

◆ intersect() [2/3]

RangeSet RangeSet::Factory::intersect ( RangeSet  What,
llvm::APSInt  Lower,
llvm::APSInt  Upper 
)

Intersect the given set with the closed range [Lower, Upper].

Unlike the Range type, this range uses modular arithmetic, corresponding to the common treatment of C integer overflow. Thus, if the Lower bound is greater than the Upper bound, the range is taken to wrap around. This is equivalent to taking the intersection with the two ranges [Min, Upper] and [Lower, Max], or, alternatively, /removing/ all integers between Upper and Lower.

Complexity: O(N) where N = size(What)

Definition at line 474 of file RangeConstraintManager.cpp.

References clang::ento::RangeSet::getMaxValue(), clang::ento::RangeSet::getMinValue(), and clang::ento::RangeSet::isEmpty().

◆ intersect() [3/3]

RangeSet RangeSet::Factory::intersect ( RangeSet  What,
llvm::APSInt  Point 
)

Intersect the given range with the given point.

The result can be either an empty set or a set containing the given point depending on whether the point is in the range set.

Complexity: O(logN) where N = size(What)

Definition at line 604 of file RangeConstraintManager.cpp.

◆ negate()

RangeSet RangeSet::Factory::negate ( RangeSet  What)

Negate the given range set.

Turn all [A, B] ranges to [-B, -A], when "-" is a C-like unary minus operation under the values of the type.

We also handle MIN because applying unary minus to MIN does not change it. Example 1: char x = -128; // -128 is a MIN value in a range of 'char' char y = -x; // y: -128

Example 2: unsigned char x = 0; // 0 is a MIN value in a range of 'unsigned char' unsigned char y = -x; // y: 0

And it makes us to separate the range like [MIN, N] to [MIN, MIN] U [-N, MAX]. For instance, whole range is {-128..127} and subrange is [-128,-126], thus [-128,-127,-126,...] negates to [-128,...,126,127].

Negate restores disrupted ranges on bounds, e.g. [MIN, B] => [MIN, MIN] U [-B, MAX] => [MIN, B].

Negate is a self-inverse function, i.e. negate(negate(R)) == R.

Complexity: O(N) where N = size(What)

Definition at line 611 of file RangeConstraintManager.cpp.

References clang::ento::RangeSet::begin(), clang::ento::RangeSet::end(), clang::ento::RangeSet::getMinValue(), clang::ento::RangeSet::isEmpty(), clang::Last, clang::Result, and clang::ento::RangeSet::size().

◆ unite() [1/4]

RangeSet RangeSet::Factory::unite ( RangeSet  LHS,
RangeSet  RHS 
)

Create a new set which is a union of two given ranges.

Possible intersections are not checked here.

Complexity: O(N + M) where N = size(LHS), M = size(RHS)

Definition at line 138 of file RangeConstraintManager.cpp.

References clang::Result.

◆ unite() [2/4]

RangeSet RangeSet::Factory::unite ( RangeSet  Original,
llvm::APSInt  From,
llvm::APSInt  To 
)

Create a new set by uniting given range set with the given range between points.

All intersections and adjacent ranges are handled here.

Complexity: O(N) where N = size(Original)

Definition at line 154 of file RangeConstraintManager.cpp.

◆ unite() [3/4]

RangeSet RangeSet::Factory::unite ( RangeSet  Original,
llvm::APSInt  Point 
)

Create a new set by uniting given range set with the given point.

All intersections and adjacent ranges are handled here.

Complexity: O(N) where N = size(Original)

Definition at line 150 of file RangeConstraintManager.cpp.

◆ unite() [4/4]

RangeSet RangeSet::Factory::unite ( RangeSet  Original,
Range  Element 
)

Create a new set by uniting given range set with the given range.

All intersections and adjacent ranges are handled here.

Complexity: O(N) where N = size(Original)

Definition at line 143 of file RangeConstraintManager.cpp.

References clang::Result.


The documentation for this class was generated from the following files: