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 22 namespace clang { 23 namespace dataflow { 24 25 /// Maps statements to the environments of basic blocks that contain them. 26 class StmtToEnvMap { 27 public: 28 StmtToEnvMap(const ControlFlowContext &CFCtx, 29 llvm::ArrayRef<std::optional<TypeErasedDataflowAnalysisState>> 30 BlockToState) 31 : CFCtx(CFCtx), BlockToState(BlockToState) {} 32 33 /// Returns the environment of the basic block that contains `S`. 34 /// The result is guaranteed never to be null. 35 const Environment *getEnvironment(const Stmt &S) const; 36 37 private: 38 const ControlFlowContext &CFCtx; 39 llvm::ArrayRef<std::optional<TypeErasedDataflowAnalysisState>> BlockToState; 40 }; 41 42 /// Evaluates `S` and updates `Env` accordingly. 43 /// 44 /// Requirements: 45 /// 46 /// `S` must not be `ParenExpr` or `ExprWithCleanups`. 47 void transfer(const StmtToEnvMap &StmtToEnv, const Stmt &S, Environment &Env); 48 49 } // namespace dataflow 50 } // namespace clang 51 52 #endif // LLVM_CLANG_ANALYSIS_FLOWSENSITIVE_TRANSFER_H 53