#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 "llvm/ADT/StringRef.h"
#include "llvm/ADT/Twine.h"
#include "llvm/Support/Error.h"
#include "llvm/Testing/ADT/StringMapEntry.h"
#include "llvm/Testing/Annotations/Annotations.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 ConstantPropagationLattice { … };
std::ostream &operator<<(std::ostream &OS,
const ConstantPropagationLattice &L) { … }
}
static constexpr char kVar[] = …;
static constexpr char kInit[] = …;
static constexpr char kJustAssignment[] = …;
static constexpr char kAssignment[] = …;
static constexpr char kRHS[] = …;
static auto refToVar() { … }
namespace {
class ConstantPropagationAnalysis
: public DataflowAnalysis<ConstantPropagationAnalysis,
ConstantPropagationLattice> { … };
AnalysisInputs;
AnalysisOutputs;
checkDataflow;
IsStringMapEntry;
UnorderedElementsAre;
MATCHER_P(HasConstantVal, v, "") { … }
MATCHER(IsUnknown, "") { … }
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(ConstantPropagationTest, JustInit) { … }
TEST(ConstantPropagationTest, TwoVariables) { … }
TEST(ConstantPropagationTest, Assignment) { … }
TEST(ConstantPropagationTest, AssignmentCall) { … }
TEST(ConstantPropagationTest, AssignmentBinOp) { … }
TEST(ConstantPropagationTest, PlusAssignment) { … }
TEST(ConstantPropagationTest, SameAssignmentInBranches) { … }
TEST(ConstantPropagationTest, SameAssignmentInBranch) { … }
TEST(ConstantPropagationTest, NewVarInBranch) { … }
TEST(ConstantPropagationTest, DifferentAssignmentInBranches) { … }
TEST(ConstantPropagationTest, DifferentAssignmentInBranch) { … }
}
}
}