clang  16.0.0git
Transfer.h
Go to the documentation of this file.
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"
19 #include "llvm/ADT/Optional.h"
20 
21 namespace clang {
22 namespace dataflow {
23 
25  /// The maximum depth to analyze. A value of zero is equivalent to disabling
26  /// context-sensitive analysis entirely.
27  unsigned Depth = 2;
28 };
29 
31  /// Options for analyzing function bodies when present in the translation
32  /// unit, or empty to disable context-sensitive analysis. Note that this is
33  /// fundamentally limited: some constructs, such as recursion, are explicitly
34  /// unsupported.
36 };
37 
38 /// Maps statements to the environments of basic blocks that contain them.
39 class StmtToEnvMap {
40 public:
41  virtual ~StmtToEnvMap() = default;
42 
43  /// Returns the environment of the basic block that contains `S` or nullptr if
44  /// there isn't one.
45  /// FIXME: Ensure that the result can't be null and return a const reference.
46  virtual const Environment *getEnvironment(const Stmt &S) const = 0;
47 };
48 
49 /// Evaluates `S` and updates `Env` accordingly.
50 ///
51 /// Requirements:
52 ///
53 /// `S` must not be `ParenExpr` or `ExprWithCleanups`.
54 void transfer(const StmtToEnvMap &StmtToEnv, const Stmt &S, Environment &Env,
55  TransferOptions Options);
56 
57 } // namespace dataflow
58 } // namespace clang
59 
60 #endif // LLVM_CLANG_ANALYSIS_FLOWSENSITIVE_TRANSFER_H
clang::dataflow::TransferOptions::ContextSensitiveOpts
llvm::Optional< ContextSensitiveOptions > ContextSensitiveOpts
Options for analyzing function bodies when present in the translation unit, or empty to disable conte...
Definition: Transfer.h:35
clang::dataflow::StmtToEnvMap::~StmtToEnvMap
virtual ~StmtToEnvMap()=default
llvm::Optional
Definition: LLVM.h:40
clang::dataflow::StmtToEnvMap::getEnvironment
virtual const Environment * getEnvironment(const Stmt &S) const =0
Returns the environment of the basic block that contains S or nullptr if there isn't one.
clang::dataflow::StmtToEnvMap
Maps statements to the environments of basic blocks that contain them.
Definition: Transfer.h:39
clang::dataflow::ContextSensitiveOptions
Definition: Transfer.h:24
DataflowEnvironment.h
clang
Definition: CalledOnceCheck.h:17
clang::dataflow::TransferOptions
Definition: Transfer.h:30
clang::Stmt
Stmt - This represents one statement.
Definition: Stmt.h:71
clang::dataflow::transfer
void transfer(const StmtToEnvMap &StmtToEnv, const Stmt &S, Environment &Env, TransferOptions Options)
Evaluates S and updates Env accordingly.
Definition: Transfer.cpp:793
Stmt.h
clang::dataflow::Environment
Holds the state of the program (store and heap) at a given program point.
Definition: DataflowEnvironment.h:65
clang::dataflow::ContextSensitiveOptions::Depth
unsigned Depth
The maximum depth to analyze.
Definition: Transfer.h:27