clang
20.0.0git
include
clang
StaticAnalyzer
Core
PathSensitive
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
"
17
#include "
clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
"
18
#include "
clang/StaticAnalyzer/Core/PathSensitive/ProgramState_Fwd.h
"
19
#include "
clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h
"
20
#include "
clang/StaticAnalyzer/Core/PathSensitive/SVals.h
"
21
#include "
clang/StaticAnalyzer/Core/PathSensitive/StoreRef.h
"
22
#include "
clang/StaticAnalyzer/Core/PathSensitive/SymExpr.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
32
namespace
clang
{
33
34
class
ASTContext;
35
class
CastExpr;
36
class
CompoundLiteralExpr;
37
class
CXXBasePath;
38
class
Decl
;
39
class
Expr;
40
class
LocationContext;
41
class
ObjCIvarDecl;
42
class
StackFrameContext;
43
44
namespace
ento {
45
46
class
CallEvent;
47
class
ProgramStateManager;
48
class
ScanReachableSymbols;
49
class
SymbolReaper;
50
51
using
InvalidatedSymbols
= llvm::DenseSet<SymbolRef>;
52
53
class
StoreManager
{
54
protected
:
55
SValBuilder
&
svalBuilder
;
56
ProgramStateManager
&
StateMgr
;
57
58
/// MRMgr - Manages region objects associated with this StoreManager.
59
MemRegionManager
&
MRMgr
;
60
ASTContext
&
Ctx
;
61
62
StoreManager
(
ProgramStateManager
&stateMgr);
63
64
public
:
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