1//===-- Transfer.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 transfer function that evaluates a program statement and
10// updates an environment accordingly.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_CLANG_ANALYSIS_FLOWSENSITIVE_TRANSFER_H
15#define LLVM_CLANG_ANALYSIS_FLOWSENSITIVE_TRANSFER_H
16
17#include "clang/AST/Stmt.h"
18#include "clang/Analysis/FlowSensitive/DataflowAnalysisContext.h"
19#include "clang/Analysis/FlowSensitive/DataflowEnvironment.h"
20#include "clang/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.h"
21
22namespace clang {
23namespace dataflow {
24
25/// Maps statements to the environments of basic blocks that contain them.
26class StmtToEnvMap {
27public:
28 // `CurBlockID` is the ID of the block currently being processed, and
29 // `CurState` is the pending state currently associated with this block. These
30 // are supplied separately as the pending state for the current block may not
31 // yet be represented in `BlockToState`.
32 StmtToEnvMap(const AdornedCFG &ACFG,
33 llvm::ArrayRef<std::optional<TypeErasedDataflowAnalysisState>>
34 BlockToState,
35 unsigned CurBlockID,
36 const TypeErasedDataflowAnalysisState &CurState)
37 : ACFG(ACFG), BlockToState(BlockToState), CurBlockID(CurBlockID),
38 CurState(CurState) {}
39
40 /// Returns the environment of the basic block that contains `S`.
41 /// The result is guaranteed never to be null.
42 const Environment *getEnvironment(const Stmt &S) const;
43
44private:
45 const AdornedCFG &ACFG;
46 llvm::ArrayRef<std::optional<TypeErasedDataflowAnalysisState>> BlockToState;
47 unsigned CurBlockID;
48 const TypeErasedDataflowAnalysisState &CurState;
49};
50
51/// Evaluates `S` and updates `Env` accordingly.
52///
53/// Requirements:
54///
55/// `S` must not be `ParenExpr` or `ExprWithCleanups`.
56void transfer(const StmtToEnvMap &StmtToEnv, const Stmt &S, Environment &Env,
57 Environment::ValueModel &Model);
58
59} // namespace dataflow
60} // namespace clang
61
62#endif // LLVM_CLANG_ANALYSIS_FLOWSENSITIVE_TRANSFER_H
63

source code of clang/include/clang/Analysis/FlowSensitive/Transfer.h