clang 20.0.0git
RangedConstraintManager.h
Go to the documentation of this file.
1//== RangedConstraintManager.h ----------------------------------*- C++ -*--==//
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// Ranged constraint manager, built on SimpleConstraintManager.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_RANGEDCONSTRAINTMANAGER_H
14#define LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_RANGEDCONSTRAINTMANAGER_H
15
19#include "llvm/ADT/APSInt.h"
20#include "llvm/Support/Allocator.h"
21
22namespace clang {
23
24namespace ento {
25
26/// A Range represents the closed range [from, to]. The caller must
27/// guarantee that from <= to. Note that Range is immutable, so as not
28/// to subvert RangeSet's immutability.
29class Range {
30public:
31 Range(const llvm::APSInt &From, const llvm::APSInt &To) : Impl(&From, &To) {
32 assert(From <= To);
33 }
34
35 Range(const llvm::APSInt &Point) : Range(Point, Point) {}
36
37 bool Includes(const llvm::APSInt &Point) const {
38 return From() <= Point && Point <= To();
39 }
40 const llvm::APSInt &From() const { return *Impl.first; }
41 const llvm::APSInt &To() const { return *Impl.second; }
42 const llvm::APSInt *getConcreteValue() const {
43 return &From() == &To() ? &From() : nullptr;
44 }
45