Coverage Report

Created: 2022-01-18 06:27

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
Line
Count
Source (jump to first uncovered line)
1
//===-- DataflowAnalysisContext.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
//  This file defines a DataflowAnalysisContext class that owns objects that
10
//  encompass the state of a program and stores context that is used during
11
//  dataflow analysis.
12
//
13
//===----------------------------------------------------------------------===//
14
15
#ifndef LLVM_CLANG_ANALYSIS_FLOWSENSITIVE_DATAFLOWANALYSISCONTEXT_H
16
#define LLVM_CLANG_ANALYSIS_FLOWSENSITIVE_DATAFLOWANALYSISCONTEXT_H
17
18
#include "clang/AST/Decl.h"
19
#include "clang/AST/Expr.h"
20
#include "clang/Analysis/FlowSensitive/StorageLocation.h"
21
#include "clang/Analysis/FlowSensitive/Value.h"
22
#include "llvm/ADT/DenseMap.h"
23
#include <cassert>
24
#include <memory>
25
#include <utility>
26
#include <vector>
27
28
namespace clang {
29
namespace dataflow {
30
31
/// Owns objects that encompass the state of a program and stores context that
32
/// is used during dataflow analysis.
33
class DataflowAnalysisContext {
34
public:
35
  /// Takes ownership of `Loc` and returns a reference to it.
36
  ///
37
  /// Requirements:
38
  ///
39
  ///  `Loc` must not be null.
40
398
  StorageLocation &takeOwnership(std::unique_ptr<StorageLocation> Loc) {
41
398
    assert(Loc != nullptr);
42
0
    Locs.push_back(std::move(Loc));
43
398
    return *Locs.back().get();
44
398
  }
45
46
  /// Takes ownership of `Val` and returns a reference to it.
47
  ///
48
  /// Requirements:
49
  ///
50
  ///  `Val` must not be null.
51
462
  Value &takeOwnership(std::unique_ptr<Value> Val) {
52
462
    assert(Val != nullptr);
53
0
    Vals.push_back(std::move(Val));
54
462
    return *Vals.back().get();
55
462
  }
56
57
  /// Assigns `Loc` as the storage location of `D`.
58
  ///
59
  /// Requirements:
60
  ///
61
  ///  `D` must not be assigned a storage location.
62
118
  void setStorageLocation(const ValueDecl &D, StorageLocation &Loc) {
63
118
    assert(DeclToLoc.find(&D) == DeclToLoc.end());
64
0
    DeclToLoc[&D] = &Loc;
65
118
  }
66
67
  /// Returns the storage location assigned to `D` or null if `D` has no
68
  /// assigned storage location.
69
203
  StorageLocation *getStorageLocation(const ValueDecl &D) const {
70
203
    auto It = DeclToLoc.find(&D);
71
203
    return It == DeclToLoc.end() ? 
nullptr118
:
It->second85
;
72
203
  }
73
74
  /// Assigns `Loc` as the storage location of `E`.
75
  ///
76
  /// Requirements:
77
  ///
78
  ///  `E` must not be assigned a storage location.
79
158
  void setStorageLocation(const Expr &E, StorageLocation &Loc) {
80
158
    assert(ExprToLoc.find(&E) == ExprToLoc.end());
81
0
    ExprToLoc[&E] = &Loc;
82
158
  }
83
84
  /// Returns the storage location assigned to `E` or null if `E` has no
85
  /// assigned storage location.
86
316
  StorageLocation *getStorageLocation(const Expr &E) const {
87
316
    auto It = ExprToLoc.find(&E);
88
316
    return It == ExprToLoc.end() ? 
nullptr158
:
It->second158
;
89
316
  }
90
91
  /// Assigns `Loc` as the storage location of the `this` pointee.
92
  ///
93
  /// Requirements:
94
  ///
95
  ///  The `this` pointee must not be assigned a storage location.
96
5
  void setThisPointeeStorageLocation(StorageLocation &Loc) {
97
5
    assert(ThisPointeeLoc == nullptr);
98
0
    ThisPointeeLoc = &Loc;
99
5
  }
100
101
  /// Returns the storage location assigned to the `this` pointee or null if the
102
  /// `this` pointee has no assigned storage location.
103
37
  StorageLocation *getThisPointeeStorageLocation() const {
104
37
    return ThisPointeeLoc;
105
37
  }
106
107
private:
108
  // Storage for the state of a program.
109
  std::vector<std::unique_ptr<StorageLocation>> Locs;
110
  std::vector<std::unique_ptr<Value>> Vals;
111
112
  // Maps from program declarations and statements to storage locations that are
113
  // assigned to them. These assignments are global (aggregated across all basic
114
  // blocks) and are used to produce stable storage locations when the same
115
  // basic blocks are evaluated multiple times. The storage locations that are
116
  // in scope for a particular basic block are stored in `Environment`.
117
  llvm::DenseMap<const ValueDecl *, StorageLocation *> DeclToLoc;
118
  llvm::DenseMap<const Expr *, StorageLocation *> ExprToLoc;
119
120
  StorageLocation *ThisPointeeLoc = nullptr;
121
122
  // FIXME: Add support for boolean expressions.
123
};
124
125
} // namespace dataflow
126
} // namespace clang
127
128
#endif // LLVM_CLANG_ANALYSIS_FLOWSENSITIVE_DATAFLOWANALYSISCONTEXT_H