clang 20.0.0git
Store.h
Go to the documentation of this file.
1//===- Store.h - Interface for maps from Locations to Values ----*- 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// This file defined the types Store and StoreManager.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_STORE_H
14#define LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_STORE_H
15
16#include "clang/AST/Type.h"
23#include "clang/Basic/LLVM.h"
24#include "llvm/ADT/ArrayRef.h"
25#include "llvm/ADT/DenseSet.h"
26#include "llvm/ADT/SmallVector.h"
27#include <cassert>
28#include <cstdint>
29#include <memory>
30#include <optional>
31
32namespace clang {
33
34class ASTContext;
35class CastExpr;
36class CompoundLiteralExpr;
37class CXXBasePath;
38class Decl;
39class Expr;
40class LocationContext;
41class ObjCIvarDecl;
42class StackFrameContext;
43
44namespace ento {
45
46class CallEvent;
47class ProgramStateManager;
48class ScanReachableSymbols;
49class SymbolReaper;
50
51using InvalidatedSymbols = llvm::DenseSet<SymbolRef>;
52
54protected:
57
58 /// MRMgr - Manages region objects associated with this StoreManager.
61
63
64public:
65 virtual ~StoreManager() = default;
66
67 /// Return the value bound to specified location in a given state.
68 /// \param[in] store The store in which to make the lookup.
69 /// \param[in] loc The symbolic memory location.
70 /// \param[in] T An optional type that provides a hint indicating the
71 /// expected type of the returned value. This is used if the value is
72 /// lazily computed.
73 /// \return The value bound to the location \c loc.
74 virtual SVal getBinding(Store store, Loc loc, QualType T = QualType()) = 0;
75
76 /// Return the default value bound to a region in a given store. The default
77 /// binding is the value of sub-regions that were not initialized separately
78 /// from their base region. For example, if the structure is zero-initialized
79 /// upon construction, this method retrieves the concrete zero value, even if
80 /// some or all fields were later overwritten manually. Default binding may be
81 /// an unknown, undefined, concrete, or symbolic value.
82 /// \param[in] store The store in which to make the lookup.
83 /// \param[in] R The region to find the default binding for.
84 /// \return The default value bound to the region in the store, if a default
85 /// binding exists.
86 virtual std::optional<SVal> getDefaultBinding(Store store,
87 const MemRegion *R) = 0;
88
89 /// Return the default value bound to a LazyCompoundVal. The default binding
90 /// is used to represent the value of any fields or elements within the
91 /// structure represented by the LazyCompoundVal which were not initialized
92 /// explicitly separately from the whole structure. Default binding may be an
93 /// unknown, undefined, concrete, or symbolic value.
94 /// \param[in] lcv The lazy compound value.
95 /// \return The default value bound to the LazyCompoundVal \c lcv, if a
96 /// default binding exists.
97 std::optional<SVal> getDefaultBinding(nonloc::LazyCompoundVal lcv) {
98 return