#include "TestingSupport.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/Decl.h"
#include "clang/AST/Expr.h"
#include "clang/AST/Stmt.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
#include "clang/ASTMatchers/ASTMatchers.h"
#include "clang/Analysis/CFG.h"
#include "clang/Analysis/FlowSensitive/DataflowAnalysis.h"
#include "clang/Analysis/FlowSensitive/DataflowEnvironment.h"
#include "clang/Analysis/FlowSensitive/DataflowLattice.h"
#include "clang/Analysis/FlowSensitive/MapLattice.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/Twine.h"
#include "llvm/Support/Error.h"
#include "llvm/Testing/ADT/StringMapEntry.h"
#include "llvm/Testing/Support/Error.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include <cstdint>
#include <memory>
#include <optional>
#include <ostream>
#include <string>
#include <utility>
namespace clang {
namespace dataflow {
namespace {
usingnamespaceast_matchers;
struct ValueLattice { … };
std::ostream &operator<<(std::ostream &OS, const ValueLattice &L) { … }
ConstantPropagationLattice;
constexpr char kDecl[] = …;
constexpr char kVar[] = …;
constexpr char kInit[] = …;
constexpr char kJustAssignment[] = …;
constexpr char kAssignment[] = …;
constexpr char kRHS[] = …;
auto refToVar() { … }
class ConstantPropagationAnalysis
: public DataflowAnalysis<ConstantPropagationAnalysis,
ConstantPropagationLattice> { … };
AnalysisInputs;
AnalysisOutputs;
checkDataflow;
IsStringMapEntry;
Pair;
UnorderedElementsAre;
MATCHER_P(Var, name,
(llvm::Twine(negation ? "isn't" : "is") + " a variable named `" +
name + "`")
.str()) { … }
MATCHER_P(HasConstantVal, v, "") { … }
MATCHER(Varies, "") { … }
MATCHER_P(HoldsCPLattice, m,
((negation ? "doesn't hold" : "holds") +
llvm::StringRef(" a lattice element that ") +
::testing::DescribeMatcher<ConstantPropagationLattice>(m, negation))
.str()) { … }
template <typename Matcher>
void RunDataflow(llvm::StringRef Code, Matcher Expectations) { … }
TEST(MultiVarConstantPropagationTest, JustInit) { … }
TEST(MultiVarConstantPropagationTest, Assignment) { … }
TEST(MultiVarConstantPropagationTest, AssignmentCall) { … }
TEST(MultiVarConstantPropagationTest, AssignmentBinOp) { … }
TEST(MultiVarConstantPropagationTest, PlusAssignment) { … }
TEST(MultiVarConstantPropagationTest, SameAssignmentInBranches) { … }
TEST(MultiVarConstantPropagationTest, TwoVariables) { … }
TEST(MultiVarConstantPropagationTest, TwoVariablesInBranches) { … }
TEST(MultiVarConstantPropagationTest, SameAssignmentInBranch) { … }
TEST(MultiVarConstantPropagationTest, NewVarInBranch) { … }
TEST(MultiVarConstantPropagationTest, DifferentAssignmentInBranches) { … }
TEST(MultiVarConstantPropagationTest, DifferentAssignmentInBranch) { … }
}
}
}