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/DataflowEnvironment.h" 19 20 namespace clang { 21 namespace dataflow { 22 23 struct TransferOptions { 24 /// Determines whether to analyze function bodies when present in the 25 /// translation unit. 26 bool ContextSensitive = false; 27 }; 28 29 /// Maps statements to the environments of basic blocks that contain them. 30 class StmtToEnvMap { 31 public: 32 virtual ~StmtToEnvMap() = default; 33 34 /// Returns the environment of the basic block that contains `S` or nullptr if 35 /// there isn't one. 36 /// FIXME: Ensure that the result can't be null and return a const reference. 37 virtual const Environment *getEnvironment(const Stmt &S) const = 0; 38 }; 39 40 /// Evaluates `S` and updates `Env` accordingly. 41 /// 42 /// Requirements: 43 /// 44 /// `S` must not be `ParenExpr` or `ExprWithCleanups`. 45 void transfer(const StmtToEnvMap &StmtToEnv, const Stmt &S, Environment &Env, 46 TransferOptions Options); 47 48 } // namespace dataflow 49 } // namespace clang 50 51 #endif // LLVM_CLANG_ANALYSIS_FLOWSENSITIVE_TRANSFER_H 52