#include "TestingSupport.h"
#include "clang/AST/Decl.h"
#include "clang/AST/ExprCXX.h"
#include "clang/AST/OperationKinds.h"
#include "clang/AST/Type.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/DataflowAnalysisContext.h"
#include "clang/Analysis/FlowSensitive/DataflowEnvironment.h"
#include "clang/Analysis/FlowSensitive/DataflowLattice.h"
#include "clang/Analysis/FlowSensitive/DebugSupport.h"
#include "clang/Analysis/FlowSensitive/NoopAnalysis.h"
#include "clang/Analysis/FlowSensitive/Value.h"
#include "clang/Analysis/FlowSensitive/WatchedLiteralsSolver.h"
#include "clang/Tooling/Tooling.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallSet.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/StringRef.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 <cassert>
#include <memory>
#include <optional>
#include <ostream>
#include <string>
#include <utility>
#include <vector>
namespace {
usingnamespaceclang;
usingnamespacedataflow;
usingnamespacetest;
usingnamespaceast_matchers;
IsStringMapEntry;
DescribeMatcher;
IsEmpty;
NotNull;
Test;
UnorderedElementsAre;
class DataflowAnalysisTest : public Test { … };
TEST_F(DataflowAnalysisTest, NoopAnalysis) { … }
TEST_F(DataflowAnalysisTest, DiagnoseFunctionDiagnoserCalledOnEachElement) { … }
TEST_F(DataflowAnalysisTest, CanAnalyzeStmt) { … }
StmtToBlockTest;
TEST_F(StmtToBlockTest, ConditionalOperator) { … }
TEST_F(StmtToBlockTest, LogicalAnd) { … }
TEST_F(StmtToBlockTest, IfStatementWithLogicalAnd) { … }
DiscardExprStateTest;
TEST_F(DiscardExprStateTest, WhileStatement) { … }
TEST_F(DiscardExprStateTest, BooleanOperator) { … }
TEST_F(DiscardExprStateTest, ConditionalOperator) { … }
TEST_F(DiscardExprStateTest, CallWithParenExprTreatedCorrectly) { … }
struct NonConvergingLattice { … };
class NonConvergingAnalysis
: public DataflowAnalysis<NonConvergingAnalysis, NonConvergingLattice> { … };
TEST_F(DataflowAnalysisTest, NonConvergingAnalysis) { … }
TEST_F(DataflowAnalysisTest, JoinBoolLValues) { … }
struct FunctionCallLattice { … };
std::ostream &operator<<(std::ostream &OS, const FunctionCallLattice &L) { … }
class FunctionCallAnalysis
: public DataflowAnalysis<FunctionCallAnalysis, FunctionCallLattice> { … };
class NoreturnDestructorTest : public Test { … };
MATCHER_P(HoldsFunctionCallLattice, m,
((negation ? "doesn't hold" : "holds") +
llvm::StringRef(" a lattice element that ") +
DescribeMatcher<FunctionCallLattice>(m))
.str()) { … }
MATCHER_P(HasCalledFunctions, m,
((negation ? "doesn't hold" : "holds") +
llvm::StringRef(" a set of called functions that ") +
DescribeMatcher<FunctionCallLattice::FunctionSet>(m))
.str()) { … }
TEST_F(NoreturnDestructorTest, ConditionalOperatorBothBranchesReturn) { … }
TEST_F(NoreturnDestructorTest, ConditionalOperatorLeftBranchReturns) { … }
TEST_F(NoreturnDestructorTest,
ConditionalOperatorConstantCondition_LeftBranchReturns) { … }
TEST_F(NoreturnDestructorTest, ConditionalOperatorRightBranchReturns) { … }
TEST_F(NoreturnDestructorTest,
ConditionalOperatorConstantCondition_RightBranchReturns) { … }
TEST_F(NoreturnDestructorTest, ConditionalOperatorNestedBranchesDoNotReturn) { … }
TEST_F(NoreturnDestructorTest, ConditionalOperatorNestedBranchReturns) { … }
class SpecialBoolAnalysis final
: public DataflowAnalysis<SpecialBoolAnalysis, NoopLattice> { … };
class JoinFlowConditionsTest : public Test { … };
TEST_F(JoinFlowConditionsTest, JoinDistinctButProvablyEquivalentValues) { … }
class NullPointerAnalysis final
: public DataflowAnalysis<NullPointerAnalysis, NoopLattice> { … };
class WideningTest : public Test { … };
TEST_F(WideningTest, JoinDistinctValuesWithDistinctProperties) { … }
TEST_F(WideningTest, JoinDistinctValuesWithSameProperties) { … }
TEST_F(WideningTest, DistinctPointersToTheSameLocationAreEquivalent) { … }
TEST_F(WideningTest, DistinctValuesWithSamePropertiesAreEquivalent) { … }
TEST_F(WideningTest, DistinctValuesWithDifferentPropertiesWidenedToTop) { … }
class FlowConditionTest : public Test { … };
TEST_F(FlowConditionTest, IfStmtSingleVar) { … }
TEST_F(FlowConditionTest, IfStmtSingleNegatedVar) { … }
TEST_F(FlowConditionTest, WhileStmt) { … }
TEST_F(FlowConditionTest, WhileStmtWithAssignmentInCondition) { … }
TEST_F(FlowConditionTest, Conjunction) { … }
TEST_F(FlowConditionTest, Disjunction) { … }
TEST_F(FlowConditionTest, NegatedConjunction) { … }
TEST_F(FlowConditionTest, DeMorgan) { … }
TEST_F(FlowConditionTest, Join) { … }
TEST_F(FlowConditionTest, OpaqueFlowConditionJoinsToOpaqueBool) { … }
TEST_F(FlowConditionTest, OpaqueFieldFlowConditionJoinsToOpaqueBool) { … }
TEST_F(FlowConditionTest, OpaqueFlowConditionInsideBranchJoinsToOpaqueBool) { … }
TEST_F(FlowConditionTest, PointerToBoolImplicitCast) { … }
class TopAnalysis final : public DataflowAnalysis<TopAnalysis, NoopLattice> { … };
class TopTest : public Test { … };
TEST_F(TopTest, UnusedTopInitializer) { … }
TEST_F(TopTest, UnusedTopAssignment) { … }
TEST_F(TopTest, UnusedTopJoinsToTop) { … }
TEST_F(TopTest, TopUsedBeforeBranchJoinsToSameAtomicBool) { … }
TEST_F(TopTest, TopUsedInBothBranchesJoinsToAtomic) { … }
TEST_F(TopTest, TopUsedInBothBranchesWithoutPrecisionLoss) { … }
TEST_F(TopTest, TopUnusedBeforeLoopHeadJoinsToTop) { … }
TEST_F(TopTest, ForRangeStmtConverges) { … }
}