llvm/clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp

//===---------- ExprMutationAnalyzerTest.cpp ------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "clang/Analysis/Analyses/ExprMutationAnalyzer.h"
#include "clang/AST/TypeLoc.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
#include "clang/ASTMatchers/ASTMatchers.h"
#include "clang/Frontend/ASTUnit.h"
#include "clang/Tooling/Tooling.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include <cctype>

namespace clang {

usingnamespaceclang::ast_matchers;
ElementsAre;
ResultOf;
Values;

namespace {

ExprMatcher;
StmtMatcher;

std::unique_ptr<ASTUnit>
buildASTFromCodeWithArgs(const Twine &Code,
                         const std::vector<std::string> &Args) {}

std::unique_ptr<ASTUnit> buildASTFromCode(const Twine &Code) {}

ExprMatcher declRefTo(StringRef Name) {}

StmtMatcher withEnclosingCompound(ExprMatcher Matcher) {}

bool isMutated(const SmallVectorImpl<BoundNodes> &Results, ASTUnit *AST) {}

bool isDeclMutated(const SmallVectorImpl<BoundNodes> &Results, ASTUnit *AST) {}

SmallVector<std::string, 1>
mutatedBy(const SmallVectorImpl<BoundNodes> &Results, ASTUnit *AST) {}

std::string removeSpace(std::string s) {}

const std::string StdRemoveReference =;

const std::string StdMove =;

const std::string StdForward =;

} // namespace

TEST(ExprMutationAnalyzerTest, Trivial) {}

class AssignmentTest : public ::testing::TestWithParam<std::string> {};

// This test is for the most basic and direct modification of a variable,
// assignment to it (e.g. `x = 10;`).
// It additionally tests that references to a variable are not only captured
// directly but expressions that result in the variable are handled, too.
// This includes the comma operator, parens and the ternary operator.
TEST_P(AssignmentTest, AssignmentModifies) {}

INSTANTIATE_TEST_SUITE_P();

TEST(ExprMutationAnalyzerTest, AssignmentConditionalWithInheritance) {}

class IncDecTest : public ::testing::TestWithParam<std::string> {};

TEST_P(IncDecTest, IncDecModifies) {}

INSTANTIATE_TEST_SUITE_P();

// Section: member functions

TEST(ExprMutationAnalyzerTest, NonConstMemberFunc) {}

TEST(ExprMutationAnalyzerTest, AssumedNonConstMemberFunc) {}

TEST(ExprMutationAnalyzerTest, ConstMemberFunc) {}

TEST(ExprMutationAnalyzerTest, TypeDependentMemberCall) {}

TEST(ExprMutationAnalyzerTest, MemberPointerMemberCall) {}

// Section: overloaded operators

TEST(ExprMutationAnalyzerTest, NonConstOperator) {}

TEST(ExprMutationAnalyzerTest, ConstOperator) {}

TEST(ExprMutationAnalyzerTest, UnresolvedOperator) {}

TEST(ExprMutationAnalyzerTest, DependentOperatorWithNonDependentOperand) {}

TEST(ExprMutationAnalyzerTest, FoldExpression) {}

// Section: expression as call argument

TEST(ExprMutationAnalyzerTest, ByValueArgument) {}

TEST(ExprMutationAnalyzerTest, ByConstValueArgument) {}

TEST(ExprMutationAnalyzerTest, ByNonConstRefArgument) {}

TEST(ExprMutationAnalyzerTest, ByNonConstRefArgumentFunctionTypeDependent) {}

TEST(ExprMutationAnalyzerTest, ByConstRefArgument) {}

TEST(ExprMutationAnalyzerTest, ByNonConstRRefArgument) {}

TEST(ExprMutationAnalyzerTest, ByConstRRefArgument) {}

// Section: bindings.

TEST(ExprMutationAnalyzerTest, BindingModifies) {}

TEST(ExprMutationAnalyzerTest, BindingDoesNotModify) {}

// section: explicit std::move and std::forward testing

TEST(ExprMutationAnalyzerTest, Move) {}

TEST(ExprMutationAnalyzerTest, Forward) {}

// section: template constellations that prohibit reasoning about modifications
//          as it depends on instantiations.

TEST(ExprMutationAnalyzerTest, CallUnresolved) {}

// section: return values

TEST(ExprMutationAnalyzerTest, ReturnAsValue) {}

TEST(ExprMutationAnalyzerTest, ReturnAsNonConstRef) {}

TEST(ExprMutationAnalyzerTest, ReturnAsConstRef) {}

TEST(ExprMutationAnalyzerTest, ReturnAsNonConstRRef) {}

TEST(ExprMutationAnalyzerTest, ReturnAsConstRRef) {}

// section: taking the address of a variable and pointers

TEST(ExprMutationAnalyzerTest, TakeAddress) {}

TEST(ExprMutationAnalyzerTest, ArrayToPointerDecay) {}

TEST(ExprMutationAnalyzerTest, TemplateWithArrayToPointerDecay) {}

// section: special case: all created references are non-mutating themself
//          and therefore all become 'const'/the value is not modified!

TEST(ExprMutationAnalyzerTest, FollowRefModified) {}

TEST(ExprMutationAnalyzerTest, FollowRefNotModified) {}

TEST(ExprMutationAnalyzerTest, FollowConditionalRefModified) {}

TEST(ExprMutationAnalyzerTest, FollowConditionalRefNotModified) {}

TEST(ExprMutationAnalyzerTest, FollowFuncArgModified) {}

TEST(ExprMutationAnalyzerTest, FollowFuncArgNotModified) {}

// section: builtin arrays

TEST(ExprMutationAnalyzerTest, ArrayElementModified) {}

TEST(ExprMutationAnalyzerTest, ArrayElementNotModified) {}

// section: member modifications

TEST(ExprMutationAnalyzerTest, NestedMemberModified) {}

TEST(ExprMutationAnalyzerTest, NestedMemberNotModified) {}

// section: casts

TEST(ExprMutationAnalyzerTest, CastToValue) {}

TEST(ExprMutationAnalyzerTest, CastToRefModified) {}

TEST(ExprMutationAnalyzerTest, CastToRefNotModified) {}

TEST(ExprMutationAnalyzerTest, CastToConstRef) {}

// section: comma expressions

TEST(ExprMutationAnalyzerTest, CommaExprWithAnAssignment) {}

TEST(ExprMutationAnalyzerTest, CommaExprWithDecOp) {}

TEST(ExprMutationAnalyzerTest, CommaExprWithNonConstMemberCall) {}

TEST(ExprMutationAnalyzerTest, CommaExprWithConstMemberCall) {}

TEST(ExprMutationAnalyzerTest, CommaExprWithCallExpr) {}

TEST(ExprMutationAnalyzerTest, CommaExprWithCallUnresolved) {}

TEST(ExprMutationAnalyzerTest, CommaExprParmRef) {}

TEST(ExprMutationAnalyzerTest, CommaExprWithAmpersandOp) {}

TEST(ExprMutationAnalyzerTest, CommaExprAsReturnAsValue) {}

TEST(ExprMutationAnalyzerTest, CommaExprAsReturnAsNonConstRef) {}

TEST(ExprMutationAnalyzerTest, CommaExprAsArrayToPointerDecay) {}

TEST(ExprMutationAnalyzerTest, CommaExprAsUniquePtr) {}

TEST(ExprMutationAnalyzerTest, CommaNestedConditional) {}

// section: lambda captures

TEST(ExprMutationAnalyzerTest, LambdaDefaultCaptureByValue) {}

TEST(ExprMutationAnalyzerTest, LambdaExplicitCaptureByValue) {}

TEST(ExprMutationAnalyzerTest, LambdaDefaultCaptureByRef) {}

TEST(ExprMutationAnalyzerTest, LambdaExplicitCaptureByRef) {}

// section: range-for loops

TEST(ExprMutationAnalyzerTest, RangeForArrayByRefModified) {}

TEST(ExprMutationAnalyzerTest, RangeForArrayByRefModifiedByImplicitInit) {}

TEST(ExprMutationAnalyzerTest, RangeForArrayByValue) {}

TEST(ExprMutationAnalyzerTest, RangeForArrayByConstRef) {}

TEST(ExprMutationAnalyzerTest, RangeForNonArrayByRefModified) {}

TEST(ExprMutationAnalyzerTest, RangeForNonArrayByRefNotModified) {}

TEST(ExprMutationAnalyzerTest, RangeForNonArrayByValue) {}

TEST(ExprMutationAnalyzerTest, RangeForNonArrayByConstRef) {}

// section: unevaluated expressions

TEST(ExprMutationAnalyzerTest, UnevaluatedExpressions) {}

TEST(ExprMutationAnalyzerTest, NotUnevaluatedExpressions) {}

// section: special case: smartpointers

TEST(ExprMutationAnalyzerTest, UniquePtr) {}

// section: complex problems detected on real code

TEST(ExprMutationAnalyzerTest, SelfRef) {}

TEST(ExprMutationAnalyzerTest, UnevaluatedContext) {}

TEST(ExprMutationAnalyzerTest, ReproduceFailureMinimal) {}
} // namespace clang