#include "TestingSupport.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/Decl.h"
#include "clang/ASTMatchers/ASTMatchers.h"
#include "clang/Analysis/FlowSensitive/DataflowAnalysisContext.h"
#include "clang/Analysis/FlowSensitive/DataflowEnvironment.h"
#include "clang/Analysis/FlowSensitive/NoopAnalysis.h"
#include "clang/Analysis/FlowSensitive/RecordOps.h"
#include "clang/Analysis/FlowSensitive/StorageLocation.h"
#include "clang/Analysis/FlowSensitive/Value.h"
#include "clang/Basic/LangStandard.h"
#include "clang/Testing/TestAST.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Testing/Support/Error.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include <optional>
#include <string>
#include <utility>
namespace clang {
namespace dataflow {
namespace {
AST_MATCHER(FunctionDecl, isTemplated) { … }
}
}
}
namespace {
usingnamespaceclang;
usingnamespacedataflow;
usingnamespacetest;
Eq;
IsNull;
Ne;
NotNull;
UnorderedElementsAre;
constexpr llvm::StringRef CoroutineLibrary = …;
void runDataflow(
llvm::StringRef Code,
std::function<
void(const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &,
ASTContext &)>
VerifyResults,
DataflowAnalysisOptions Options,
LangStandard::Kind Std = LangStandard::lang_cxx17,
llvm::StringRef TargetFun = "target") { … }
void runDataflow(
llvm::StringRef Code,
std::function<
void(const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &,
ASTContext &)>
VerifyResults,
LangStandard::Kind Std = LangStandard::lang_cxx17,
bool ApplyBuiltinTransfer = true, llvm::StringRef TargetFun = "target") { … }
void runDataflowOnLambda(
llvm::StringRef Code,
std::function<
void(const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &,
ASTContext &)>
VerifyResults,
DataflowAnalysisOptions Options,
LangStandard::Kind Std = LangStandard::lang_cxx17) { … }
void runDataflowOnLambda(
llvm::StringRef Code,
std::function<
void(const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &,
ASTContext &)>
VerifyResults,
LangStandard::Kind Std = LangStandard::lang_cxx17,
bool ApplyBuiltinTransfer = true) { … }
const Formula &getFormula(const ValueDecl &D, const Environment &Env) { … }
TEST(TransferTest, CNotSupported) { … }
TEST(TransferTest, ObjectiveCNotSupported) { … }
TEST(TransferTest, ObjectiveCXXNotSupported) { … }
TEST(TransferTest, IntVarDeclNotTrackedWhenTransferDisabled) { … }
TEST(TransferTest, BoolVarDecl) { … }
TEST(TransferTest, IntVarDecl) { … }
TEST(TransferTest, StructIncomplete) { … }
TEST(TransferTest, StructFieldUnmodeled) { … }
TEST(TransferTest, StructVarDecl) { … }
TEST(TransferTest, StructVarDeclWithInit) { … }
TEST(TransferTest, StructArrayVarDecl) { … }
TEST(TransferTest, ClassVarDecl) { … }
TEST(TransferTest, ReferenceVarDecl) { … }
TEST(TransferTest, SelfReferentialReferenceVarDecl) { … }
TEST(TransferTest, PointerVarDecl) { … }
TEST(TransferTest, SelfReferentialPointerVarDecl) { … }
TEST(TransferTest, DirectlySelfReferentialReference) { … }
TEST(TransferTest, MultipleVarsDecl) { … }
TEST(TransferTest, JoinVarDecl) { … }
TEST(TransferTest, BinaryOperatorAssign) { … }
TEST(TransferTest, BinaryOperatorAssignIntegerLiteral) { … }
TEST(TransferTest, VarDeclInitAssign) { … }
TEST(TransferTest, VarDeclInitAssignChained) { … }
TEST(TransferTest, VarDeclInitAssignPtrDeref) { … }
TEST(TransferTest, AssignToAndFromReference) { … }
TEST(TransferTest, MultipleParamDecls) { … }
TEST(TransferTest, StructParamDecl) { … }
TEST(TransferTest, ReferenceParamDecl) { … }
TEST(TransferTest, PointerParamDecl) { … }
TEST(TransferTest, StructMember) { … }
TEST(TransferTest, StructMemberEnum) { … }
TEST(TransferTest, DerivedBaseMemberClass) { … }
static void derivedBaseMemberExpectations(
const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
ASTContext &ASTCtx) { … }
TEST(TransferTest, DerivedBaseMemberStructDefault) { … }
TEST(TransferTest, DerivedBaseMemberPrivateFriend) { … }
TEST(TransferTest, ClassMember) { … }
TEST(TransferTest, BaseClassInitializer) { … }
TEST(TransferTest, FieldsDontHaveValuesInConstructor) { … }
TEST(TransferTest, FieldsDontHaveValuesInConstructorWithBaseClass) { … }
TEST(TransferTest, StructModeledFieldsWithAccessor) { … }
TEST(TransferTest, StructModeledFieldsInTypeid) { … }
TEST(TransferTest, StructModeledFieldsWithComplicatedInheritance) { … }
TEST(TransferTest, StructInitializerListWithComplicatedInheritance) { … }
TEST(TransferTest, ReferenceMember) { … }
TEST(TransferTest, StructThisMember) { … }
TEST(TransferTest, ClassThisMember) { … }
TEST(TransferTest, UnionThisMember) { … }
TEST(TransferTest, StructThisInLambda) { … }
TEST(TransferTest, ConstructorInitializer) { … }
TEST(TransferTest, DefaultInitializer) { … }
TEST(TransferTest, DefaultInitializerReference) { … }
TEST(TransferTest, TemporaryObject) { … }
TEST(TransferTest, ElidableConstructor) { … }
TEST(TransferTest, AssignmentOperator) { … }
TEST(TransferTest, AssignmentOperator_ArgByValue) { … }
TEST(TransferTest, AssignmentOperatorFromBase) { … }
TEST(TransferTest, AssignmentOperatorFromCallResult) { … }
TEST(TransferTest, AssignmentOperatorWithInitAndInheritance) { … }
TEST(TransferTest, AssignmentOperatorReturnsVoid) { … }
TEST(TransferTest, AssignmentOperatorReturnsByValue) { … }
TEST(TransferTest, AssignmentOperatorReturnsDifferentTypeByRef) { … }
TEST(TransferTest, AssignmentOperatorReturnsDifferentTypeByValue) { … }
TEST(TransferTest, InitListExprAsXValue) { … }
TEST(TransferTest, ArrayInitListExprOneRecordElement) { … }
TEST(TransferTest, InitListExprAsUnion) { … }
TEST(TransferTest, EmptyInitListExprForUnion) { … }
TEST(TransferTest, EmptyInitListExprForStruct) { … }
TEST(TransferTest, CopyConstructor) { … }
TEST(TransferTest, CopyConstructorWithDefaultArgument) { … }
TEST(TransferTest, CopyConstructorWithParens) { … }
TEST(TransferTest, CopyConstructorWithInitializerListAsSyntacticSugar) { … }
TEST(TransferTest, CopyConstructorArgIsRefReturnedByFunction) { … }
TEST(TransferTest, MoveConstructor) { … }
TEST(TransferTest, BindTemporary) { … }
TEST(TransferTest, ResultObjectLocation) { … }
TEST(TransferTest, ResultObjectLocationForDefaultArgExpr) { … }
TEST(TransferTest, ResultObjectLocationForDefaultInitExpr) { … }
TEST(TransferTest, ResultObjectLocationForCXXOperatorCallExpr) { … }
TEST(TransferTest, ResultObjectLocationForInitListExpr) { … }
TEST(TransferTest, ResultObjectLocationForParenInitListExpr) { … }
TEST(TransferTest, ResultObjectLocationForBuiltinSpaceshipOperator) { … }
TEST(TransferTest, ResultObjectLocationForStdInitializerListExpr) { … }
TEST(TransferTest, ResultObjectLocationForStmtExpr) { … }
TEST(TransferTest, ResultObjectLocationForBuiltinBitCastExpr) { … }
TEST(TransferTest, ResultObjectLocationForAtomicExpr) { … }
TEST(TransferTest, ResultObjectLocationPropagatesThroughConditionalOperator) { … }
TEST(TransferTest, ResultObjectLocationDontVisitNestedRecordDecl) { … }
TEST(TransferTest, ResultObjectLocationDontVisitUnevaluatedContexts) { … }
TEST(TransferTest, StaticCast) { … }
TEST(TransferTest, IntegralCast) { … }
TEST(TransferTest, IntegraltoBooleanCast) { … }
TEST(TransferTest, IntegralToBooleanCastFromBool) { … }
TEST(TransferTest, WidenBoolValueInIntegerVariable) { … }
TEST(TransferTest, NullToPointerCast) { … }
TEST(TransferTest, PointerToMemberVariable) { … }
TEST(TransferTest, PointerToMemberFunction) { … }
TEST(TransferTest, NullToMemberPointerCast) { … }
TEST(TransferTest, AddrOfValue) { … }
TEST(TransferTest, AddrOfReference) { … }
TEST(TransferTest, Preincrement) { … }
TEST(TransferTest, Postincrement) { … }
TEST(TransferTest, AddAssign) { … }
TEST(TransferTest, CannotAnalyzeFunctionTemplate) { … }
TEST(TransferTest, CannotAnalyzeMethodOfClassTemplate) { … }
TEST(TransferTest, VarDeclInitAssignConditionalOperator) { … }
TEST(TransferTest, VarDeclInDoWhile) { … }
TEST(TransferTest, UnreachableAfterWhileTrue) { … }
TEST(TransferTest, AggregateInitialization) { … }
TEST(TransferTest, AggregateInitializationReferenceField) { … }
TEST(TransferTest, AggregateInitialization_NotExplicitlyInitializedField) { … }
TEST(TransferTest, AggregateInitializationFunctionPointer) { … }
TEST(TransferTest, AssignToUnionMember) { … }
TEST(TransferTest, AssignFromBoolLiteral) { … }
TEST(TransferTest, AssignFromCompositeBoolExpression) { … }
TEST(TransferTest, AssignFromBoolNegation) { … }
TEST(TransferTest, BuiltinExpect) { … }
TEST(TransferTest, BuiltinExpectBoolArg) { … }
TEST(TransferTest, BuiltinUnreachable) { … }
TEST(TransferTest, BuiltinTrap) { … }
TEST(TransferTest, BuiltinDebugTrap) { … }
TEST(TransferTest, StaticIntSingleVarDecl) { … }
TEST(TransferTest, StaticIntGroupVarDecl) { … }
TEST(TransferTest, GlobalIntVarDecl) { … }
TEST(TransferTest, StaticMemberIntVarDecl) { … }
TEST(TransferTest, StaticMemberRefVarDecl) { … }
TEST(TransferTest, AssignMemberBeforeCopy) { … }
TEST(TransferTest, BooleanEquality) { … }
TEST(TransferTest, BooleanInequality) { … }
TEST(TransferTest, PointerEquality) { … }
TEST(TransferTest, PointerEqualityUnionMembers) { … }
TEST(TransferTest, IntegerLiteralEquality) { … }
TEST(TransferTest, CorrelatedBranches) { … }
TEST(TransferTest, LoopWithAssignmentConverges) { … }
TEST(TransferTest, LoopWithStagedAssignments) { … }
TEST(TransferTest, LoopWithReferenceAssignmentConverges) { … }
TEST(TransferTest, LoopWithStructReferenceAssignmentConverges) { … }
TEST(TransferTest, LoopDereferencingChangingPointerConverges) { … }
TEST(TransferTest, LoopDereferencingChangingRecordPointerConverges) { … }
TEST(TransferTest, LoopWithShortCircuitedConditionConverges) { … }
TEST(TransferTest, LoopCanProveInvariantForBoolean) { … }
TEST(TransferTest, DoesNotCrashOnUnionThisExpr) { … }
TEST(TransferTest, DoesNotCrashOnNullChildren) { … }
TEST(TransferTest, StructuredBindingAssignFromStructIntMembersToRefs) { … }
TEST(TransferTest, StructuredBindingAssignFromStructRefMembersToRefs) { … }
TEST(TransferTest, StructuredBindingAssignFromStructIntMembersToInts) { … }
TEST(TransferTest, StructuredBindingAssignFromTupleLikeType) { … }
TEST(TransferTest, StructuredBindingAssignRefFromTupleLikeType) { … }
TEST(TransferTest, BinaryOperatorComma) { … }
TEST(TransferTest, ConditionalOperatorValue) { … }
TEST(TransferTest, ConditionalOperatorLocation) { … }
TEST(TransferTest, ConditionalOperatorOnConstantExpr) { … }
TEST(TransferTest, IfStmtBranchExtendsFlowCondition) { … }
TEST(TransferTest, WhileStmtBranchExtendsFlowCondition) { … }
TEST(TransferTest, DoWhileStmtBranchExtendsFlowCondition) { … }
TEST(TransferTest, ForStmtBranchExtendsFlowCondition) { … }
TEST(TransferTest, ForStmtBranchWithoutConditionDoesNotExtendFlowCondition) { … }
TEST(TransferTest, ContextSensitiveOptionDisabled) { … }
TEST(TransferTest, ContextSensitiveReturnReference) { … }
TEST(TransferTest, ContextSensitiveReturnReferenceWithConditionalOperator) { … }
TEST(TransferTest, ContextSensitiveReturnOneOfTwoReferences) { … }
TEST(TransferTest, ContextSensitiveDepthZero) { … }
TEST(TransferTest, ContextSensitiveSetTrue) { … }
TEST(TransferTest, ContextSensitiveSetFalse) { … }
TEST(TransferTest, ContextSensitiveSetBothTrueAndFalse) { … }
TEST(TransferTest, ContextSensitiveSetTwoLayersDepthOne) { … }
TEST(TransferTest, ContextSensitiveSetTwoLayersDepthTwo) { … }
TEST(TransferTest, ContextSensitiveSetThreeLayersDepthTwo) { … }
TEST(TransferTest, ContextSensitiveSetThreeLayersDepthThree) { … }
TEST(TransferTest, ContextSensitiveMutualRecursion) { … }
TEST(TransferTest, ContextSensitiveSetMultipleLines) { … }
TEST(TransferTest, ContextSensitiveSetMultipleBlocks) { … }
TEST(TransferTest, ContextSensitiveReturnVoid) { … }
TEST(TransferTest, ContextSensitiveReturnTrue) { … }
TEST(TransferTest, ContextSensitiveReturnFalse) { … }
TEST(TransferTest, ContextSensitiveReturnArg) { … }
TEST(TransferTest, ContextSensitiveReturnInt) { … }
TEST(TransferTest, ContextSensitiveReturnRecord) { … }
TEST(TransferTest, ContextSensitiveReturnSelfReferentialRecord) { … }
TEST(TransferTest, ContextSensitiveMethodLiteral) { … }
TEST(TransferTest, ContextSensitiveMethodGetter) { … }
TEST(TransferTest, ContextSensitiveMethodSetter) { … }
TEST(TransferTest, ContextSensitiveMethodGetterAndSetter) { … }
TEST(TransferTest, ContextSensitiveMethodTwoLayersVoid) { … }
TEST(TransferTest, ContextSensitiveMethodTwoLayersReturn) { … }
TEST(TransferTest, ContextSensitiveConstructorBody) { … }
TEST(TransferTest, ContextSensitiveConstructorInitializer) { … }
TEST(TransferTest, ContextSensitiveConstructorDefault) { … }
TEST(TransferTest, ContextSensitiveSelfReferentialClass) { … }
TEST(TransferTest, UnnamedBitfieldInitializer) { … }
TEST(TransferTest, ChainedLogicalOps) { … }
TEST(TransferTest, NoReturnFunctionInsideShortCircuitedBooleanOp) { … }
TEST(TransferTest, NewExpressions) { … }
TEST(TransferTest, NewExpressions_Structs) { … }
TEST(TransferTest, FunctionToPointerDecayHasValue) { … }
TEST(TransferTest, BuiltinFunctionModeled) { … }
TEST(TransferTest, MemberOperatorCallModelsPointerForCallee) { … }
TEST(TransferTest, AnonymousStruct) { … }
TEST(TransferTest, AnonymousStructWithInitializer) { … }
TEST(TransferTest, AnonymousStructWithReferenceField) { … }
TEST(TransferTest, EvaluateBlockWithUnreachablePreds) { … }
TEST(TransferTest, LambdaCaptureByCopy) { … }
TEST(TransferTest, LambdaCaptureByReference) { … }
TEST(TransferTest, LambdaCaptureWithInitializer) { … }
TEST(TransferTest, LambdaCaptureByCopyImplicit) { … }
TEST(TransferTest, LambdaCaptureByReferenceImplicit) { … }
TEST(TransferTest, LambdaCaptureThis) { … }
TEST(TransferTest, ConditionalRelation) { … }
TEST(TransferTest, AnonymousUnionMemberExprInTemplate) { … }
}