Use LLVM style consistently for names in test snippets.
PiperOrigin-RevId: 671755329
Change-Id: Ib175db5e3cf0c37de3d37606369b679c7c1c8814
diff --git a/nullability/inference/collect_evidence_test.cc b/nullability/inference/collect_evidence_test.cc
index 41bc45d..4a1793c 100644
--- a/nullability/inference/collect_evidence_test.cc
+++ b/nullability/inference/collect_evidence_test.cc
@@ -63,8 +63,8 @@
constexpr llvm::StringRef CheckMacroDefinitions = R"cc(
// Bodies must reference the first param so that args are in the AST, but
// otherwise don't matter.
-#define CHECK(x) (x)
-#define CHECK_NE(a, b) (a, b)
+#define CHECK(X) (X)
+#define CHECK_NE(A, B) (A, B)
)cc";
MATCHER_P3(isEvidenceMatcher, SlotMatcher, KindMatcher, SymbolMatcher, "") {
@@ -163,21 +163,30 @@
return collectFromDefinition(AST, Definition, Pragmas, InputInferences);
}
-std::vector<Evidence> collectFromTargetDecl(llvm::StringRef Source) {
+std::vector<Evidence> collectFromDecl(llvm::StringRef Source,
+ llvm::StringRef DeclName) {
std::vector<Evidence> Results;
NullabilityPragmas Pragmas;
clang::TestAST AST(getAugmentedTestInputs(Source, Pragmas));
USRCache USRCache;
collectEvidenceFromTargetDeclaration(
- *dataflow::test::findValueDecl(AST.context(), "target"),
+ *dataflow::test::findValueDecl(AST.context(), DeclName),
evidenceEmitter([&](const Evidence& E) { Results.push_back(E); },
USRCache, AST.context()),
Pragmas);
return Results;
}
+auto collectFromTargetVarDecl(llvm::StringRef Source) {
+ return collectFromDecl(Source, "Target");
+}
+
+auto collectFromTargetFuncDecl(llvm::StringRef Source) {
+ return collectFromDecl(Source, "target");
+}
+
TEST(CollectEvidenceFromDefinitionTest, Location) {
- llvm::StringRef Code = "void target(int *p) { *p; }";
+ llvm::StringRef Code = "void target(int *P) { *P; }";
// 12345678901234567890123456
// 0 1 2
@@ -189,7 +198,7 @@
TEST(SmartPointerCollectEvidenceFromDefinitionTest, Location) {
llvm::StringRef Code =
- "#include <memory>\nvoid target(std::unique_ptr<int> p) { *p; }";
+ "#include <memory>\nvoid target(std::unique_ptr<int> P) { *P; }";
// 123456789012345678901234567890123456789012
// 0 1 2 3 4
@@ -208,16 +217,16 @@
TEST(CollectEvidenceFromDefinitionTest, OneParamUnused) {
static constexpr llvm::StringRef Src = R"cc(
- void target(int *p0) {}
+ void target(int *P) {}
)cc";
EXPECT_THAT(collectFromTargetFuncDefinition(Src), IsEmpty());
}
TEST(CollectEvidenceFromDefinitionTest, OneParamUsedWithoutRestriction) {
static constexpr llvm::StringRef Src = R"cc(
- void takesUnknown(int *unknown) {}
+ void takesUnknown(int *Unknown) {}
- void target(int *p0) { takesUnknown(p0); }
+ void target(int *P) { takesUnknown(P); }
)cc";
EXPECT_THAT(collectFromTargetFuncDefinition(Src),
Not(Contains(evidence(_, _, functionNamed("target")))));
@@ -225,10 +234,10 @@
TEST(CollectEvidenceFromDefinitionTest, Deref) {
static constexpr llvm::StringRef Src = R"cc(
- void target(int *p0, int *p1) {
- int a = *p0;
- if (p1 != nullptr) {
- int b = *p1;
+ void target(int *P0, int *P1) {
+ int A = *P0;
+ if (P1 != nullptr) {
+ int B = *P1;
}
}
)cc";
@@ -240,12 +249,12 @@
TEST(CollectEvidenceFromDefinitionTest, DerefArrow) {
static constexpr llvm::StringRef Src = R"cc(
struct S {
- int x;
+ int X;
int y();
};
- void target(S *a, S *b) {
- a->x;
- b->y();
+ void target(S *A, S *B) {
+ A->X;
+ B->y();
}
)cc";
EXPECT_THAT(collectFromTargetFuncDefinition(Src),
@@ -258,13 +267,13 @@
static constexpr llvm::StringRef Src = R"cc(
#include <memory>
struct S {
- int x;
+ int X;
int y();
};
- void target(std::unique_ptr<S> p) {
- *p;
- p->x;
- p->y();
+ void target(std::unique_ptr<S> P) {
+ *P;
+ P->X;
+ P->y();
}
)cc";
EXPECT_THAT(collectFromTargetFuncDefinition(Src),
@@ -276,8 +285,8 @@
TEST(CollectEvidenceFromDefinitionTest, DerefOfNonnull) {
static constexpr llvm::StringRef Src = R"cc(
- void target(Nonnull<int *> p) {
- *p;
+ void target(Nonnull<int *> P) {
+ *P;
}
)cc";
EXPECT_THAT(collectFromTargetFuncDefinition(Src), IsEmpty());
@@ -285,10 +294,10 @@
TEST(CollectEvidenceFromDefinitionTest, DereferenceBeforeAssignment) {
static constexpr llvm::StringRef Src = R"cc(
- void target(int *p) {
- *p;
- int i = 1;
- p = &i;
+ void target(int *P) {
+ *P;
+ int I = 1;
+ P = &I;
}
)cc";
EXPECT_THAT(
@@ -298,10 +307,10 @@
TEST(CollectEvidenceFromDefinitionTest, DereferenceAfterAssignment) {
static constexpr llvm::StringRef Src = R"cc(
- void target(int *p) {
- int i = 1;
- p = &i;
- *p;
+ void target(int *P) {
+ int I = 1;
+ P = &I;
+ *P;
}
)cc";
EXPECT_THAT(collectFromTargetFuncDefinition(Src),
@@ -312,11 +321,11 @@
static constexpr llvm::StringRef Src = R"cc(
int& getIntRef();
int* getIntPtr();
- void target(int* p) {
- p = &getIntRef();
- *p;
- p = getIntPtr();
- *p;
+ void target(int* P) {
+ P = &getIntRef();
+ *P;
+ P = getIntPtr();
+ *P;
}
)cc";
EXPECT_THAT(collectFromTargetFuncDefinition(Src),
@@ -326,10 +335,10 @@
TEST(CollectEvidenceFromDefinitionTest, DerefOfPtrRef) {
static constexpr llvm::StringRef Src = R"cc(
- void target(int *&p0, int *&p1) {
- int a = *p0;
- if (p1 != nullptr) {
- int b = *p1;
+ void target(int *&P0, int *&P1) {
+ int A = *P0;
+ if (P1 != nullptr) {
+ int B = *P1;
}
}
)cc";
@@ -340,13 +349,13 @@
TEST(CollectEvidenceFromDefinitionTest, UnrelatedCondition) {
static constexpr llvm::StringRef Src = R"cc(
- void target(int *p0, int *p1, int *p2, bool b) {
- if (b) {
- int a = *p0;
- int b = *p1;
+ void target(int *P0, int *P1, int *P2, bool B) {
+ if (B) {
+ int A = *P0;
+ int B = *P1;
} else {
- int a = *p0;
- int c = *p2;
+ int A = *P0;
+ int C = *P2;
}
}
)cc";
@@ -354,20 +363,20 @@
UnorderedElementsAre(
evidence(paramSlot(0), Evidence::UNCHECKED_DEREFERENCE),
evidence(paramSlot(1), Evidence::UNCHECKED_DEREFERENCE),
- // We collect two Evidence values for two dereferences of p0
+ // We collect two Evidence values for two dereferences of P0
evidence(paramSlot(0), Evidence::UNCHECKED_DEREFERENCE),
evidence(paramSlot(2), Evidence::UNCHECKED_DEREFERENCE)));
}
TEST(CollectEvidenceFromDefinitionTest, LaterDeref) {
static constexpr llvm::StringRef Src = R"cc(
- void target(int *p0) {
- if (p0 == nullptr) {
+ void target(int *P) {
+ if (P == nullptr) {
(void)0;
} else {
(void)0;
}
- int a = *p0;
+ int A = *P;
}
)cc";
EXPECT_THAT(collectFromTargetFuncDefinition(Src),
@@ -377,10 +386,10 @@
TEST(CollectEvidenceFromDefinitionTest, DerefBeforeGuardedDeref) {
static constexpr llvm::StringRef Src = R"cc(
- void target(int *p0) {
- int a = *p0;
- if (p0 != nullptr) {
- int b = *p0;
+ void target(int *P) {
+ int A = *P;
+ if (P != nullptr) {
+ int B = *P;
}
}
)cc";
@@ -391,15 +400,15 @@
TEST(CollectEvidenceFromDefinitionTest, DerefAndOrCheckOfCopiedPtr) {
static constexpr llvm::StringRef Src = R"cc(
- void target(int* p, int* q) {
- int* a = p;
- *a;
- int* b = q;
- if (q) {
- *b;
+ void target(int* P, int* Q) {
+ int* A = P;
+ *A;
+ int* B = Q;
+ if (Q) {
+ *B;
}
- if (b) {
- *q;
+ if (B) {
+ *Q;
}
}
)cc";
@@ -407,44 +416,44 @@
UnorderedElementsAre(
evidence(paramSlot(0), Evidence::UNCHECKED_DEREFERENCE),
evidence(Slot(0), Evidence::ASSIGNED_FROM_UNKNOWN,
- localVarNamed("a")),
+ localVarNamed("A")),
evidence(Slot(0), Evidence::ASSIGNED_FROM_UNKNOWN,
- localVarNamed("b"))));
+ localVarNamed("B"))));
}
TEST(CollectEvidenceFromDefinitionTest, FirstSufficientSlotOnly) {
static constexpr llvm::StringRef Src = R"cc(
- void target(int* p, int* q) {
- // Marking either of p or q Nonnull is sufficient to avoid dereferencing
+ void target(int* P, int* Q) {
+ // Marking either of P or Q Nonnull is sufficient to avoid dereferencing
// without a check. We choose to record evidence only for the first
// sufficient slot which can be Nonnull without the dereference becoming
// dead code.
- int* a;
- if (p) {
- a = p;
+ int* A;
+ if (P) {
+ A = P;
} else {
- a = q;
+ A = Q;
}
- *a;
+ *A;
}
)cc";
EXPECT_THAT(collectFromTargetFuncDefinition(Src),
UnorderedElementsAre(
evidence(paramSlot(0), Evidence::UNCHECKED_DEREFERENCE),
evidence(Slot(0), Evidence::ASSIGNED_FROM_NONNULL,
- localVarNamed("a")),
+ localVarNamed("A")),
evidence(Slot(0), Evidence::ASSIGNED_FROM_UNKNOWN,
- localVarNamed("a"))));
+ localVarNamed("A"))));
}
TEST(CollectEvidenceFromDefinitionTest,
FirstSufficientSlotNotContradictingFlowConditions) {
static constexpr llvm::StringRef Src = R"cc(
- void target(int* p, int* q) {
- // Marking p Nonnull would make the dereference dead, so we collect
- // evidence for q being Nonnull instead, since it is also sufficient.
- if (!p) {
- *q;
+ void target(int* P, int* Q) {
+ // Marking P Nonnull would make the dereference dead, so we collect
+ // evidence for Q being Nonnull instead, since it is also sufficient.
+ if (!P) {
+ *Q;
}
}
)cc";
@@ -455,11 +464,11 @@
TEST(CollectEvidenceFromDefinitionTest, EarlyReturn) {
static constexpr llvm::StringRef Src = R"cc(
- void target(int *p0) {
- if (!p0) {
+ void target(int *P) {
+ if (!P) {
return;
}
- int a = *p0;
+ int A = *P;
}
)cc";
EXPECT_THAT(collectFromTargetFuncDefinition(Src), IsEmpty());
@@ -467,19 +476,19 @@
TEST(CollectEvidenceFromDefinitionTest, UnreachableCode) {
static constexpr llvm::StringRef Src = R"cc(
- void target(int *p0, int *p1, int *p2, int *p3) {
+ void target(int *P0, int *P1, int *P2, int *P3) {
if (true) {
- int a = *p0;
+ int A = *P0;
} else {
- int a = *p1;
+ int A = *P1;
}
if (false) {
- int a = *p2;
+ int A = *P2;
}
return;
- int a = *p3;
+ int A = *P3;
}
)cc";
EXPECT_THAT(collectFromTargetFuncDefinition(Src),
@@ -491,10 +500,10 @@
static constexpr llvm::StringRef Src = R"cc(
struct S {};
- void target(int S::*p) {
- S s;
- s.*p;
- (&s)->*p;
+ void target(int S::*P) {
+ S AnS;
+ AnS.*P;
+ (&AnS)->*P;
}
)cc";
// Pointers to members are not supported pointer types, so no evidence is
@@ -507,10 +516,10 @@
static constexpr llvm::StringRef Src = R"cc(
struct S {};
- void target(void (S::*p)()) {
- S s;
- (s.*p)();
- ((&s)->*p)();
+ void target(void (S::*P)()) {
+ S AnS;
+ (AnS.*P)();
+ ((&AnS)->*P)();
}
)cc";
@@ -524,41 +533,41 @@
static constexpr llvm::StringRef Src = R"cc(
struct S {};
- void target(void (S::*p)(Nonnull<int*> i, int* j), int* q) {
- S s;
- (s.*p)(q, nullptr);
- ((&s)->*p)(q, nullptr);
+ void target(void (S::*P)(Nonnull<int*> I, int* J), int* Q) {
+ S AnS;
+ (AnS.*P)(Q, nullptr);
+ ((&AnS)->*P)(Q, nullptr);
}
)cc";
// Pointers to members are not supported pointer types, so no evidence is
- // collected for `p` or `j`. If they become a supported pointer type, this
+ // collected for `P` or `J`. If they become a supported pointer type, this
// test should start failing.
- // TODO(b/309625642) We should still collect evidence for the use of `q` as an
- // argument for param `i`.
+ // TODO(b/309625642) We should still collect evidence for the use of `Q` as an
+ // argument for param `I`.
EXPECT_THAT(collectFromTargetFuncDefinition(Src), IsEmpty());
}
TEST(CollectEvidenceFromDefinitionTest, CheckMacro) {
llvm::Twine Src = CheckMacroDefinitions + R"cc(
- void target(int* p, int* q, int* r, int* s, int* t, int* u, int* v) {
+ void target(int* P, int* Q, int* R, int* S, int* T, int* U, int* V) {
// should collect evidence for params from these calls
- CHECK(p);
- CHECK(q != nullptr);
- int* a = nullptr;
- CHECK(r != a);
- CHECK(a != s);
- bool b = t != nullptr;
- CHECK(b);
+ CHECK(P);
+ CHECK(Q != nullptr);
+ int* A = nullptr;
+ CHECK(R != A);
+ CHECK(A != S);
+ bool B = T != nullptr;
+ CHECK(B);
// should not crash when analyzing these calls
- CHECK(u == v);
- CHECK(u != v);
+ CHECK(U == V);
+ CHECK(U != V);
CHECK(1);
- struct S {
+ struct ConvertibleToBool {
operator bool() const { return true; }
};
- CHECK(S());
+ CHECK(ConvertibleToBool());
CHECK(true);
CHECK(false); // must come last because it's detected as causing the rest
// of the function to be dead.
@@ -572,17 +581,17 @@
evidence(paramSlot(3), Evidence::ABORT_IF_NULL),
evidence(paramSlot(4), Evidence::ABORT_IF_NULL),
evidence(Slot(0), Evidence::ASSIGNED_FROM_NULLABLE,
- localVarNamed("a"))));
+ localVarNamed("A"))));
}
TEST(SmartPointerCollectEvidenceFromDefinitionTest, CheckMacro) {
llvm::Twine Src = CheckMacroDefinitions + R"cc(
#include <memory>
- void target(std::unique_ptr<int> p, std::unique_ptr<int> q,
- std::unique_ptr<int> r) {
- CHECK(p);
- CHECK(!!q);
- CHECK(r.get());
+ void target(std::unique_ptr<int> P, std::unique_ptr<int> Q,
+ std::unique_ptr<int> R) {
+ CHECK(P);
+ CHECK(!!Q);
+ CHECK(R.get());
}
)cc";
EXPECT_THAT(
@@ -594,24 +603,24 @@
TEST(CollectEvidenceFromDefinitionTest, CheckNEMacro) {
llvm::Twine Src = CheckMacroDefinitions + R"cc(
- void target(int* p, int* q, int* r, int* s) {
+ void target(int* P, int* Q, int* R, int* S) {
// should collect evidence for params from these calls
- CHECK_NE(p, nullptr);
- CHECK_NE(nullptr, q);
- int* a = nullptr;
- CHECK_NE(a, r);
- CHECK_NE(s, a);
+ CHECK_NE(P, nullptr);
+ CHECK_NE(nullptr, Q);
+ int* A = nullptr;
+ CHECK_NE(A, R);
+ CHECK_NE(S, A);
// should not crash when analyzing these calls
- CHECK_NE(a, 0);
- int i = 1;
- CHECK_NE(i, 0);
- bool b = true;
+ CHECK_NE(A, 0);
+ int I = 1;
+ CHECK_NE(I, 0);
+ bool B = true;
CHECK_NE(true, false);
- struct S {
- bool operator==(const S&) const { return false; }
+ struct ConvertibleToBool {
+ bool operator==(const ConvertibleToBool&) const { return false; }
};
- CHECK_NE(S(), S());
+ CHECK_NE(ConvertibleToBool(), ConvertibleToBool());
}
)cc";
EXPECT_THAT(
@@ -621,18 +630,18 @@
evidence(paramSlot(2), Evidence::ABORT_IF_NULL),
evidence(paramSlot(3), Evidence::ABORT_IF_NULL),
evidence(Slot(0), Evidence::ASSIGNED_FROM_NULLABLE,
- localVarNamed("a"))));
+ localVarNamed("A"))));
}
TEST(SmartPointerCollectEvidenceFromDefinitionTest, CheckNEMacro) {
llvm::Twine Src = CheckMacroDefinitions + R"cc(
#include <memory>
- void target(std::unique_ptr<int> p, std::unique_ptr<int> q,
- std::unique_ptr<int> r, std::unique_ptr<int> s) {
- CHECK_NE(p, nullptr);
- CHECK_NE(nullptr, q);
- if (!r) {
- CHECK_NE(s, r);
+ void target(std::unique_ptr<int> P, std::unique_ptr<int> Q,
+ std::unique_ptr<int> R, std::unique_ptr<int> S) {
+ CHECK_NE(P, nullptr);
+ CHECK_NE(nullptr, Q);
+ if (!R) {
+ CHECK_NE(S, R);
}
}
)cc";
@@ -645,8 +654,8 @@
TEST(CollectEvidenceFromDefinitionTest, NullableArgPassed) {
static constexpr llvm::StringRef Src = R"cc(
- void callee(int *q);
- void target(Nullable<int *> p) { callee(p); }
+ void callee(int *Q);
+ void target(Nullable<int *> P) { callee(P); }
)cc";
EXPECT_THAT(collectFromTargetFuncDefinition(Src),
Contains(evidence(paramSlot(0), Evidence::NULLABLE_ARGUMENT,
@@ -655,8 +664,8 @@
TEST(CollectEvidenceFromDefinitionTest, NonnullArgPassed) {
static constexpr llvm::StringRef Src = R"cc(
- void callee(int *q);
- void target(Nonnull<int *> p) { callee(p); }
+ void callee(int *Q);
+ void target(Nonnull<int *> P) { callee(P); }
)cc";
EXPECT_THAT(collectFromTargetFuncDefinition(Src),
Contains(evidence(paramSlot(0), Evidence::NONNULL_ARGUMENT,
@@ -665,8 +674,8 @@
TEST(CollectEvidenceFromDefinitionTest, UnknownArgPassed) {
static constexpr llvm::StringRef Src = R"cc(
- void callee(int *q);
- void target(int *p) { callee(p); }
+ void callee(int *Q);
+ void target(int *P) { callee(P); }
)cc";
EXPECT_THAT(collectFromTargetFuncDefinition(Src),
Contains(evidence(paramSlot(0), Evidence::UNKNOWN_ARGUMENT,
@@ -675,10 +684,10 @@
TEST(CollectEvidenceFromDefinitionTest, UnknownButProvablyNullArgPassed) {
static constexpr llvm::StringRef Src = R"cc(
- void callee(int *q);
- void target(int *p) {
- if (p == nullptr) {
- callee(p);
+ void callee(int *Q);
+ void target(int *P) {
+ if (P == nullptr) {
+ callee(P);
}
}
)cc";
@@ -689,9 +698,9 @@
TEST(CollectEvidenceFromDefinitionTest, CheckedArgPassed) {
static constexpr llvm::StringRef Src = R"cc(
- void callee(int *q);
- void target(int *p) {
- if (p) callee(p);
+ void callee(int *Q);
+ void target(int *P) {
+ if (P) callee(P);
}
)cc";
EXPECT_THAT(collectFromTargetFuncDefinition(Src),
@@ -701,11 +710,11 @@
TEST(CollectEvidenceFromDefinitionTest, NullptrPassed) {
static constexpr llvm::StringRef Src = R"cc(
- void callee(int* q);
+ void callee(int* Q);
void target() {
callee(nullptr);
- int* p = nullptr;
- callee(p);
+ int* P = nullptr;
+ callee(P);
}
)cc";
EXPECT_THAT(
@@ -715,24 +724,24 @@
evidence(paramSlot(0), Evidence::NULLABLE_ARGUMENT,
functionNamed("callee")),
evidence(Slot(0), Evidence::ASSIGNED_FROM_NULLABLE,
- localVarNamed("p"))));
+ localVarNamed("P"))));
}
TEST(CollectEvidenceFromDefinitionTest, NonPtrArgPassed) {
static constexpr llvm::StringRef Src = R"cc(
- void callee(int q);
- void target(int p) { callee(p); }
+ void callee(int Q);
+ void target(int P) { callee(P); }
)cc";
EXPECT_THAT(collectFromTargetFuncDefinition(Src), IsEmpty());
}
TEST(CollectEvidenceFromDefinitionTest, ReferenceArgsPassed) {
static constexpr llvm::StringRef Src = R"cc(
- void constCallee(int* const& a, int* const& b, int* const& c);
- void mutableCallee(int*& a, int*& b, int*& c);
- void target(Nullable<int*> p, Nonnull<int*> q, int* r) {
- constCallee(p, q, r);
- mutableCallee(p, q, r);
+ void constCallee(int* const& A, int* const& B, int* const& C);
+ void mutableCallee(int*& A, int*& B, int*& C);
+ void target(Nullable<int*> P, Nonnull<int*> Q, int* R) {
+ constCallee(P, Q, R);
+ mutableCallee(P, Q, R);
}
)cc";
EXPECT_THAT(collectFromTargetFuncDefinition(Src),
@@ -755,11 +764,11 @@
static constexpr llvm::StringRef Src = R"cc(
#include <memory>
#include <utility>
- void callee(std::unique_ptr<int> p, Nonnull<std::unique_ptr<int>> q,
- Nullable<std::unique_ptr<int>>& r);
- void target(Nullable<std::unique_ptr<int>> a, std::unique_ptr<int> b,
- std::unique_ptr<int> c) {
- callee(std::move(a), std::move(b), c);
+ void callee(std::unique_ptr<int> P, Nonnull<std::unique_ptr<int>> Q,
+ Nullable<std::unique_ptr<int>>& R);
+ void target(Nullable<std::unique_ptr<int>> A, std::unique_ptr<int> B,
+ std::unique_ptr<int> C) {
+ callee(std::move(A), std::move(B), C);
}
)cc";
EXPECT_THAT(collectFromTargetFuncDefinition(Src),
@@ -781,10 +790,10 @@
static constexpr llvm::StringRef Src = R"cc(
int* getDefault();
void hasDefaultUnannotatedFunc(int* = getDefault());
- int* q = nullptr;
+ int* Q = nullptr;
void hasDefaultUnannotatedVariable(int* = getDefault());
- int i = 1;
- void hasDefaultExpressionOfVariable(int* = &i);
+ int I = 1;
+ void hasDefaultExpressionOfVariable(int* = &I);
void target() {
hasDefaultUnannotatedFunc();
hasDefaultUnannotatedVariable();
@@ -805,8 +814,8 @@
TEST(CollectEvidenceFromDefinitionTest, NullableButCheckedReturn) {
static constexpr llvm::StringRef Src = R"cc(
- int* target(Nullable<int*> p) {
- if (p) return p;
+ int* target(Nullable<int*> P) {
+ if (P) return P;
// no return in this path to avoid irrelevant evidence, and this still
// compiles, as the lack of return in a path is only a warning.
@@ -819,8 +828,8 @@
TEST(CollectEvidenceFromDefinitionTest, NonnullReturn) {
static constexpr llvm::StringRef Src = R"cc(
- int* target(Nonnull<int*> p) {
- return p;
+ int* target(Nonnull<int*> P) {
+ return P;
}
)cc";
EXPECT_THAT(collectFromTargetFuncDefinition(Src),
@@ -830,7 +839,7 @@
TEST(CollectEvidenceFromDefinitionTest, UnknownReturn) {
static constexpr llvm::StringRef Src = R"cc(
- int* target(int* p) { return p; }
+ int* target(int* P) { return P; }
)cc";
EXPECT_THAT(collectFromTargetFuncDefinition(Src),
UnorderedElementsAre(
@@ -839,9 +848,9 @@
TEST(CollectEvidenceFromDefinitionTest, UnknownButProvablyNullReturn) {
static constexpr llvm::StringRef Src = R"cc(
- int* target(int* p) {
- if (p == nullptr) {
- return p;
+ int* target(int* P) {
+ if (P == nullptr) {
+ return P;
}
// no return in this path to avoid irrelevant evidence, and this still
// compiles, as the lack of return in a path is only a warning.
@@ -854,10 +863,10 @@
TEST(CollectEvidenceFromDefinitionTest, MultipleReturns) {
static constexpr llvm::StringRef Src = R"cc(
- int* target(Nonnull<int*> p, Nullable<int*> q, bool b, bool c) {
- if (b) return q;
- if (c) return nullptr;
- return p;
+ int* target(Nonnull<int*> P, Nullable<int*> Q, bool B, bool C) {
+ if (B) return Q;
+ if (C) return nullptr;
+ return P;
}
)cc";
EXPECT_THAT(collectFromTargetFuncDefinition(Src),
@@ -869,10 +878,10 @@
TEST(CollectEvidenceFromDefinitionTest, ReferenceReturns) {
static constexpr llvm::StringRef Src = R"cc(
- int*& target(Nonnull<int*>& p, Nullable<int*>& q, int*& r, bool a, bool b) {
- if (a) return p;
- if (b) return q;
- return r;
+ int*& target(Nonnull<int*>& P, Nullable<int*>& Q, int*& R, bool A, bool B) {
+ if (A) return P;
+ if (B) return Q;
+ return R;
}
)cc";
EXPECT_THAT(
@@ -885,8 +894,8 @@
TEST(CollectEvidenceFromDefinitionTest, FromReturnAnnotation) {
static constexpr llvm::StringRef Src = R"cc(
- Nonnull<int*> target(int* a) {
- return a;
+ Nonnull<int*> target(int* A) {
+ return A;
}
)cc";
EXPECT_THAT(collectFromTargetFuncDefinition(Src),
@@ -897,7 +906,7 @@
TEST(CollectEvidenceFromDefinitionTest,
FromPreviouslyInferredReturnAnnotation) {
static constexpr llvm::StringRef Src = R"cc(
- int* target(int* a) { return a; }
+ int* target(int* A) { return A; }
)cc";
EXPECT_THAT(
collectFromTargetFuncDefinition(
@@ -917,8 +926,8 @@
// The pragma applies to the int* deduced for the `auto` return type,
// making the return type Nonnull<int*>.
- auto target(NullabilityUnknown<int*> a, bool b) {
- if (b) return a;
+ auto target(NullabilityUnknown<int*> A, bool B) {
+ if (B) return A;
return getNonnull();
}
)cc";
@@ -944,14 +953,14 @@
TEST(SmartPointerCollectEvidenceFromDefinitionTest, MultipleReturns) {
static constexpr llvm::StringRef Src = R"cc(
#include <memory>
- std::unique_ptr<int> target(Nonnull<std::unique_ptr<int>> p,
- Nullable<std::unique_ptr<int>> q,
- std::unique_ptr<int> r, bool a, bool b,
- bool c) {
- if (a) return nullptr;
- if (b) return p;
- if (c) return q;
- return r;
+ std::unique_ptr<int> target(Nonnull<std::unique_ptr<int>> P,
+ Nullable<std::unique_ptr<int>> Q,
+ std::unique_ptr<int> R, bool A, bool B,
+ bool C) {
+ if (A) return nullptr;
+ if (B) return P;
+ if (C) return Q;
+ return R;
}
)cc";
EXPECT_THAT(collectFromTargetFuncDefinition(Src),
@@ -965,8 +974,8 @@
TEST(SmartPointerCollectEvidenceFromDefinitionTest, FromReturnAnnotation) {
static constexpr llvm::StringRef Src = R"cc(
#include <memory>
- Nonnull<std::unique_ptr<int>> target(std::unique_ptr<int> a) {
- return a;
+ Nonnull<std::unique_ptr<int>> target(std::unique_ptr<int> A) {
+ return A;
}
)cc";
EXPECT_THAT(collectFromTargetFuncDefinition(Src),
@@ -990,8 +999,8 @@
static constexpr llvm::StringRef Src = R"cc(
int* makePtr();
void target() {
- auto p = makePtr();
- *p;
+ auto P = makePtr();
+ *P;
}
)cc";
EXPECT_THAT(
@@ -1005,8 +1014,8 @@
static constexpr llvm::StringRef Src = R"cc(
int* makePtr();
void target() {
- auto p = makePtr();
- if (p) *p;
+ auto P = makePtr();
+ if (P) *P;
}
)cc";
EXPECT_THAT(
@@ -1019,9 +1028,9 @@
FunctionCallResultDereferencedAfterUnrelatedConditionChecked) {
static constexpr llvm::StringRef Src = R"cc(
int* makePtr();
- void target(bool cond) {
- auto p = makePtr();
- if (cond) *p;
+ void target(bool Cond) {
+ auto P = makePtr();
+ if (Cond) *P;
}
)cc";
EXPECT_THAT(
@@ -1056,7 +1065,7 @@
TEST(CollectEvidenceFromDefinitionTest, FunctionPointerCall) {
static constexpr llvm::StringRef Src = R"cc(
- void target(void (*f)()) { f(); }
+ void target(void (*F)()) { F(); }
)cc";
EXPECT_THAT(collectFromTargetFuncDefinition(Src),
UnorderedElementsAre(
@@ -1070,18 +1079,18 @@
struct Pair {
Pair();
- A a;
- B b;
+ A AnA;
+ B AB;
};
- void target(int *i) {
- Pair<void (*)(Nonnull<int *>), bool> p;
- auto [fp, b] = p;
- fp(i);
+ void target(int *I) {
+ Pair<void (*)(Nonnull<int *>), bool> P;
+ auto [FP, B] = P;
+ FP(I);
}
)cc";
- // Ideally, we would see the Nonnull from `p`'s template parameter and collect
- // ASSIGNED_TO_NONNULL evidence for `i`, but the sugar doesn't carry through
+ // Ideally, we would see the Nonnull from `P`'s template parameter and collect
+ // ASSIGNED_TO_NONNULL evidence for `I`, but the sugar doesn't carry through
// the BindingDecl's `auto` type.
EXPECT_THAT(collectFromTargetFuncDefinition(Src), IsEmpty());
}
@@ -1089,13 +1098,13 @@
TEST(CollectEvidenceFromDefinitionTest, ConstAccessorDereferencedAfterCheck) {
static constexpr llvm::StringRef Src = R"cc(
struct S {
- int* accessor() const { return i; }
- int* i = nullptr;
+ int* accessor() const { return I; }
+ int* I = nullptr;
};
void target() {
- S s;
- if (s.accessor() != nullptr) {
- *s.accessor();
+ S AnS;
+ if (AnS.accessor() != nullptr) {
+ *AnS.accessor();
}
}
)cc";
@@ -1108,13 +1117,13 @@
ReferenceConstAccessorDereferencedAfterCheck) {
static constexpr llvm::StringRef Src = R"cc(
struct S {
- int* const& accessor() const { return i; }
- int* i = nullptr;
+ int* const& accessor() const { return I; }
+ int* I = nullptr;
};
void target() {
- S s;
- if (s.accessor() != nullptr) {
- *s.accessor();
+ S AnS;
+ if (AnS.accessor() != nullptr) {
+ *AnS.accessor();
}
}
)cc";
@@ -1128,8 +1137,8 @@
ConstAccessorOnTwoDifferentObjectsDereferencedAfterCheck) {
static constexpr llvm::StringRef Src = R"cc(
struct S {
- int* const& accessor() const { return i; }
- int* i = nullptr;
+ int* const& accessor() const { return I; }
+ int* I = nullptr;
};
S makeS();
@@ -1152,8 +1161,8 @@
int* operator()();
};
void target() {
- S s;
- *s();
+ S AnS;
+ *AnS();
}
)cc";
EXPECT_THAT(
@@ -1212,9 +1221,9 @@
TEST(CollectEvidenceFromDefinitionTest, ConstructorCall) {
static constexpr llvm::StringRef Src = R"cc(
struct S {
- S(Nonnull<int*> a);
+ S(Nonnull<int*> A);
};
- void target(int* p) { S s(p); }
+ void target(int* P) { S AnS(P); }
)cc";
EXPECT_THAT(
collectFromTargetFuncDefinition(Src),
@@ -1229,10 +1238,10 @@
template <typename T>
struct S {
// Not a target due to templating, but the annotation here can still
- // provide evidence for `p` from the call in `target`'s body.
- S(Nonnull<T*> a);
+ // provide evidence for `P` from the call in `target`'s body.
+ S(Nonnull<T*> A);
};
- void target(int* p) { S s(p); }
+ void target(int* P) { S AnS(P); }
)cc";
EXPECT_THAT(
collectFromTargetFuncDefinition(Src),
@@ -1245,35 +1254,35 @@
struct TakeNonnull {
explicit TakeNonnull(Nonnull<int *>);
};
- struct target : TakeNonnull {
- target(int *i) : TakeNonnull(i) {}
+ struct Target : TakeNonnull {
+ Target(int *I) : TakeNonnull(I) {}
};
)cc";
- EXPECT_THAT(collectFromTargetFuncDefinition(Src),
+ EXPECT_THAT(collectFromDefinitionNamed("Target", Src),
Contains(evidence(paramSlot(0), Evidence::ASSIGNED_TO_NONNULL,
- functionNamed("target"))));
+ functionNamed("Target"))));
}
TEST(CollectEvidenceFromDefinitionTest, ConstructorWithDelegatingConstructor) {
static constexpr llvm::StringRef Src = R"cc(
- struct target {
- target(int* i);
- target() : target(nullptr){};
+ struct Target {
+ Target(int* I);
+ Target() : Target(nullptr) {};
};
)cc";
EXPECT_THAT(collectFromDefinitionMatching(
- functionDecl(hasName("target"), parameterCountIs(0)), Src),
+ functionDecl(hasName("Target"), parameterCountIs(0)), Src),
Contains(evidence(paramSlot(0), Evidence::NULLABLE_ARGUMENT,
- functionNamed("target"))));
+ functionNamed("Target"))));
}
TEST(CollectEvidenceFromDefinitionTest, VariadicConstructorCall) {
static constexpr llvm::StringRef Src = R"cc(
struct S {
- S(Nonnull<int*> i, ...);
+ S(Nonnull<int*> I, ...);
};
- void target(int* p, int* q) { S s(p, q); }
+ void target(int* P, int* Q) { S AnS(P, Q); }
)cc";
EXPECT_THAT(
collectFromTargetFuncDefinition(Src),
@@ -1574,9 +1583,9 @@
TEST(CollectEvidenceFromDefinitionTest, PassedToNonnull) {
static constexpr llvm::StringRef Src = R"cc(
- void callee(Nonnull<int*> i);
+ void callee(Nonnull<int*> I);
- void target(int* p) { callee(p); }
+ void target(int* P) { callee(P); }
)cc";
EXPECT_THAT(
collectFromTargetFuncDefinition(Src),
@@ -1588,9 +1597,9 @@
TEST(CollectEvidenceFromDefinitionTest, PassedToNonnullRef) {
static constexpr llvm::StringRef Src = R"cc(
- void callee(Nonnull<int*>& i);
+ void callee(Nonnull<int*>& I);
- void target(int* p) { callee(p); }
+ void target(int* P) { callee(P); }
)cc";
EXPECT_THAT(collectFromTargetFuncDefinition(Src),
UnorderedElementsAre(
@@ -1603,12 +1612,12 @@
TEST(CollectEvidenceFromDefinitionTest, PassedToNonnullInMemberFunction) {
static constexpr llvm::StringRef Src = R"cc(
struct S {
- void callee(Nonnull<int*> i);
+ void callee(Nonnull<int*> I);
};
- void target(int* p) {
- S s;
- s.callee(p);
+ void target(int* P) {
+ S AnS;
+ AnS.callee(P);
}
)cc";
EXPECT_THAT(
@@ -1621,8 +1630,8 @@
TEST(CollectEvidenceFromDefinitionTest, PassedToNonnullInFunctionPointerParam) {
static constexpr llvm::StringRef Src = R"cc(
- void target(int* p, void (*callee)(Nonnull<int*> i)) {
- callee(p);
+ void target(int* P, void (*Callee)(Nonnull<int*> I)) {
+ Callee(P);
}
)cc";
EXPECT_THAT(collectFromTargetFuncDefinition(Src),
@@ -1638,9 +1647,9 @@
static constexpr llvm::StringRef Src = R"cc(
#include <memory>
#include <utility>
- void target(std::unique_ptr<int*> p,
- void (*callee)(Nonnull<std::unique_ptr<int*>> i)) {
- callee(std::move(p));
+ void target(std::unique_ptr<int*> P,
+ void (*Callee)(Nonnull<std::unique_ptr<int*>> I)) {
+ Callee(std::move(P));
}
)cc";
EXPECT_THAT(collectFromTargetFuncDefinition(Src),
@@ -1654,25 +1663,25 @@
TEST(CollectEvidenceFromDefinitionTest, PassedToNonnullInFunctionPointerField) {
static constexpr llvm::StringRef Src = R"cc(
struct MyStruct {
- void (*callee)(Nonnull<int*>);
+ void (*Callee)(Nonnull<int*>);
};
- void target(int* p) { MyStruct().callee(p); }
+ void target(int* P) { MyStruct().Callee(P); }
)cc";
EXPECT_THAT(
collectFromTargetFuncDefinition(Src),
UnorderedElementsAre(evidence(paramSlot(0), Evidence::ASSIGNED_TO_NONNULL,
functionNamed("target")),
evidence(Slot(0), Evidence::UNCHECKED_DEREFERENCE,
- fieldNamed("MyStruct::callee"))));
+ fieldNamed("MyStruct::Callee"))));
}
TEST(CollectEvidenceFromDefinitionTest,
PassedToNonnullInFunctionPointerFromAddressOfFunctionDecl) {
static constexpr llvm::StringRef Src = R"cc(
- void callee(Nonnull<int*> i);
+ void callee(Nonnull<int*> I);
- void target(int* p) { (&callee)(p); }
+ void target(int* P) { (&callee)(P); }
)cc";
EXPECT_THAT(
collectFromTargetFuncDefinition(Src),
@@ -1685,8 +1694,8 @@
TEST(CollectEvidenceFromDefinitionTest,
PassedToNonnullInFunctionReferenceParam) {
static constexpr llvm::StringRef Src = R"cc(
- void target(int* p, void (&callee)(Nonnull<int*> i)) {
- callee(p);
+ void target(int* P, void (&Callee)(Nonnull<int*> I)) {
+ Callee(P);
}
)cc";
EXPECT_THAT(
@@ -1698,8 +1707,8 @@
TEST(CollectEvidenceFromDefinitionTest,
PassedToNonnullInFunctionPointerReferenceParam) {
static constexpr llvm::StringRef Src = R"cc(
- void target(int* p, void (*&callee)(Nonnull<int*> i)) {
- callee(p);
+ void target(int* P, void (*&Callee)(Nonnull<int*> I)) {
+ Callee(P);
}
)cc";
EXPECT_THAT(collectFromTargetFuncDefinition(Src),
@@ -1712,7 +1721,7 @@
TEST(CollectEvidenceFromDefinitionTest, FunctionCallPassedToNonnull) {
static constexpr llvm::StringRef Src = R"cc(
- void callee(Nonnull<int*> i);
+ void callee(Nonnull<int*> I);
int* makeIntPtr();
void target() { callee(makeIntPtr()); }
@@ -1730,7 +1739,7 @@
static constexpr llvm::StringRef Src = R"cc(
int* makeIntPtr();
- void target(void (*callee)(Nonnull<int*> i)) { callee(makeIntPtr()); }
+ void target(void (*Callee)(Nonnull<int*> I)) { Callee(makeIntPtr()); }
)cc";
EXPECT_THAT(collectFromTargetFuncDefinition(Src),
UnorderedElementsAre(
@@ -1746,13 +1755,13 @@
int* makeIntPtr();
template <typename T>
- void target(void (*callee)(Nonnull<T*> i), int* a) {
- callee(makeIntPtr());
- *a;
+ void target(void (*Callee)(Nonnull<T*> I), int* A) {
+ Callee(makeIntPtr());
+ *A;
}
void instantiate() {
- target<int>([](Nonnull<int*> i) {}, nullptr);
+ target<int>([](Nonnull<int*> I) {}, nullptr);
}
)cc";
// Doesn't collect any evidence for target from target's body, only collects
@@ -1767,9 +1776,9 @@
TEST(CollectEvidenceFromDefinitionTest, PassedToNullable) {
static constexpr llvm::StringRef Src = R"cc(
- void callee(Nullable<int*> i);
+ void callee(Nullable<int*> I);
- void target(int* p) { callee(p); }
+ void target(int* P) { callee(P); }
)cc";
EXPECT_THAT(collectFromTargetFuncDefinition(Src),
Not(Contains(evidence(_, _, functionNamed("target")))));
@@ -1777,9 +1786,9 @@
TEST(CollectEvidenceFromDefinitionTest, PassedToNullableRef) {
static constexpr llvm::StringRef Src = R"cc(
- void callee(Nullable<int*>& i);
+ void callee(Nullable<int*>& I);
- void target(int* p) { callee(p); }
+ void target(int* P) { callee(P); }
)cc";
EXPECT_THAT(collectFromTargetFuncDefinition(Src),
UnorderedElementsAre(
@@ -1792,12 +1801,12 @@
TEST(CollectEvidenceFromDefinitionTest,
PassedToNullableRefFromStoredFunctionCall) {
static constexpr llvm::StringRef Src = R"cc(
- void callee(Nullable<int*>& i);
+ void callee(Nullable<int*>& I);
int* producer();
void target() {
- auto p = producer();
- callee(p);
+ auto P = producer();
+ callee(P);
}
)cc";
EXPECT_THAT(
@@ -1808,12 +1817,12 @@
evidence(paramSlot(0), Evidence::UNKNOWN_REFERENCE_ARGUMENT,
functionNamed("callee")),
evidence(Slot(0), Evidence::ASSIGNED_FROM_UNKNOWN,
- localVarNamed("p", "target"))));
+ localVarNamed("P", "target"))));
}
TEST(CollectEvidenceFromDefinitionTest, PassedToNullableRefFromFunctionCall) {
static constexpr llvm::StringRef Src = R"cc(
- void callee(Nullable<int*>& i);
+ void callee(Nullable<int*>& I);
int*& producer();
void target() { callee(producer()); }
@@ -1830,9 +1839,9 @@
TEST(CollectEvidenceFromDefinitionTest,
InitializationOfAndAssignmentToNonnull) {
static constexpr llvm::StringRef Src = R"cc(
- void target(int* p, int* q, int* r) {
- Nonnull<int*> a = p, b = q;
- a = r;
+ void target(int* P, int* Q, int* R) {
+ Nonnull<int*> A = P, B = Q;
+ A = R;
}
)cc";
EXPECT_THAT(collectFromTargetFuncDefinition(Src),
@@ -1847,19 +1856,19 @@
static constexpr llvm::StringRef Src = R"cc(
#include <memory>
#include <utility>
- struct S {
- Nonnull<std::unique_ptr<int>> a;
+ struct SomeType {
+ Nonnull<std::unique_ptr<int>> Field;
Nonnull<std::unique_ptr<int>>& getRef();
};
- void target(std::unique_ptr<int> p, Nonnull<std::unique_ptr<int>> q,
- std::unique_ptr<int> r, std::unique_ptr<int> s,
- std::unique_ptr<int> t) {
- q = std::move(p);
- S AnS;
- AnS.a = std::move(r);
- AnS.getRef() = std::move(s);
- Nonnull<std::unique_ptr<int>> nonnull = std::move(t);
+ void target(std::unique_ptr<int> P, Nonnull<std::unique_ptr<int>> Q,
+ std::unique_ptr<int> R, std::unique_ptr<int> S,
+ std::unique_ptr<int> T) {
+ Q = std::move(P);
+ SomeType SomeObject;
+ SomeObject.Field = std::move(R);
+ SomeObject.getRef() = std::move(S);
+ Nonnull<std::unique_ptr<int>> nonnull = std::move(T);
}
)cc";
EXPECT_THAT(collectFromTargetFuncDefinition(Src),
@@ -1872,8 +1881,8 @@
TEST(CollectEvidenceFromDefinitionTest, InitializationOfNonnullRefFromRef) {
static constexpr llvm::StringRef Src = R"cc(
- void target(int*& p) {
- Nonnull<int*>& a = p;
+ void target(int*& P) {
+ Nonnull<int*>& A = P;
}
)cc";
EXPECT_THAT(collectFromTargetFuncDefinition(Src),
@@ -1888,7 +1897,7 @@
template <typename T>
void target() {
- Nonnull<T*> p = makeIntPtr();
+ Nonnull<T*> P = makeIntPtr();
}
void instantiate() { target<int>(); }
@@ -1907,26 +1916,26 @@
TEST(CollectEvidenceFromDefinitionTest,
InitializationOfAndAssignmentToNullableOrUnknown) {
static constexpr llvm::StringRef Src = R"cc(
- void target(int* p, int* q, int* r) {
- Nullable<int*> a = p;
- int* b = q;
- NullabilityUnknown<int*> c = r;
- q = r;
+ void target(int* P, int* Q, int* R) {
+ Nullable<int*> A = P;
+ int* B = Q;
+ NullabilityUnknown<int*> C = R;
+ Q = R;
}
)cc";
EXPECT_THAT(collectFromTargetFuncDefinition(Src),
UnorderedElementsAre(
evidence(paramSlot(1), Evidence::ASSIGNED_FROM_UNKNOWN),
evidence(Slot(0), Evidence::ASSIGNED_FROM_UNKNOWN,
- localVarNamed("b")),
+ localVarNamed("B")),
evidence(Slot(0), Evidence::ASSIGNED_FROM_UNKNOWN,
- localVarNamed("c"))));
+ localVarNamed("C"))));
}
TEST(CollectEvidenceFromDefinitionTest, InitializationOfNullableRef) {
static constexpr llvm::StringRef Src = R"cc(
- void target(int* p) {
- Nullable<int*>& a = p;
+ void target(int* P) {
+ Nullable<int*>& A = P;
}
)cc";
EXPECT_THAT(collectFromTargetFuncDefinition(Src),
@@ -1938,8 +1947,8 @@
InitializationOfNullableRef) {
static constexpr llvm::StringRef Src = R"cc(
#include <memory>
- void target(std::unique_ptr<int> p) {
- Nullable<std::unique_ptr<int>>& a = p;
+ void target(std::unique_ptr<int> P) {
+ Nullable<std::unique_ptr<int>>& A = P;
}
)cc";
EXPECT_THAT(collectFromTargetFuncDefinition(Src),
@@ -1950,8 +1959,8 @@
TEST(CollectEvidenceFromDefinitionTest, InitializationOfNullableRefFromRef) {
static constexpr llvm::StringRef Src = R"cc(
- void target(int*& p) {
- Nullable<int*>& a = p;
+ void target(int*& P) {
+ Nullable<int*>& A = P;
}
)cc";
EXPECT_THAT(collectFromTargetFuncDefinition(Src),
@@ -1966,8 +1975,8 @@
TEST(CollectEvidenceFromDefinitionTest,
DISABLED_InitializationOfNullableRefAllConnectedDecls) {
static constexpr llvm::StringRef Src = R"cc(
- void target(int* p, int* q, bool b) {
- Nullable<int*>& x = b ? p : q;
+ void target(int* P, int* Q, bool B) {
+ Nullable<int*>& X = B ? P : Q;
}
)cc";
EXPECT_THAT(
@@ -1979,8 +1988,8 @@
TEST(CollectEvidenceFromDefinitionTest, AssignedFromNullptr) {
static constexpr llvm::StringRef Src = R"cc(
- void target(int* p) {
- p = nullptr;
+ void target(int* P) {
+ P = nullptr;
}
)cc";
EXPECT_THAT(collectFromTargetFuncDefinition(Src),
@@ -1990,21 +1999,21 @@
TEST(CollectEvidenceFromDefinitionTest, AssignedFromNullptrIndirect) {
static constexpr llvm::StringRef Src = R"cc(
- void target(int* p) {
- int* a = nullptr;
- p = a;
+ void target(int* P) {
+ int* A = nullptr;
+ P = A;
}
)cc";
EXPECT_THAT(collectFromTargetFuncDefinition(Src),
UnorderedElementsAre(
evidence(paramSlot(0), Evidence::ASSIGNED_FROM_NULLABLE),
evidence(Slot(0), Evidence::ASSIGNED_FROM_NULLABLE,
- localVarNamed("a"))));
+ localVarNamed("A"))));
}
TEST(CollectEvidenceFromDefinitionTest, AssignedFromZero) {
static constexpr llvm::StringRef Src = R"cc(
- void target(int* p) { p = 0; }
+ void target(int* P) { P = 0; }
)cc";
EXPECT_THAT(collectFromTargetFuncDefinition(Src),
UnorderedElementsAre(
@@ -2014,7 +2023,7 @@
TEST(CollectEvidenceFromDefinitionTest, AssignedFromNullable) {
static constexpr llvm::StringRef Src = R"cc(
Nullable<int*> getNullable();
- void target(int* p) { p = getNullable(); }
+ void target(int* P) { P = getNullable(); }
)cc";
EXPECT_THAT(collectFromTargetFuncDefinition(Src),
UnorderedElementsAre(evidence(paramSlot(0),
@@ -2024,9 +2033,9 @@
TEST(CollectEvidenceFromDefinitionTest, AssignedFromLocalNullable) {
static constexpr llvm::StringRef Src = R"cc(
- void target(int* p) {
- Nullable<int*> a;
- p = a;
+ void target(int* P) {
+ Nullable<int*> A;
+ P = A;
}
)cc";
EXPECT_THAT(collectFromTargetFuncDefinition(Src),
@@ -2050,8 +2059,8 @@
TEST(CollectEvidenceFromDefinitionTest, AssignedFromNullptrMultipleOperators) {
static constexpr llvm::StringRef Src = R"cc(
- void target(int* p) {
- *&p = nullptr;
+ void target(int* P) {
+ *&P = nullptr;
}
)cc";
EXPECT_THAT(collectFromTargetFuncDefinition(Src),
@@ -2068,8 +2077,8 @@
static constexpr llvm::StringRef Src = R"cc(
int* foo();
void target() {
- Nullable<int*> p = foo();
- p = nullptr;
+ Nullable<int*> P = foo();
+ P = nullptr;
}
)cc";
EXPECT_THAT(collectFromTargetFuncDefinition(Src), IsEmpty());
@@ -2077,9 +2086,9 @@
TEST(CollectEvidenceFromDefinitionTest, AssignedFromNonnull) {
static constexpr llvm::StringRef Src = R"cc(
- void target(int* p) {
- int a = 0;
- p = &a;
+ void target(int* P) {
+ int A = 0;
+ P = &A;
}
)cc";
EXPECT_THAT(collectFromTargetFuncDefinition(Src),
@@ -2089,8 +2098,8 @@
TEST(CollectEvidenceFromDefinitionTest, AssignedFromUnknown) {
static constexpr llvm::StringRef Src = R"cc(
- void target(int* p, int* q) {
- p = q;
+ void target(int* P, int* Q) {
+ P = Q;
}
)cc";
EXPECT_THAT(collectFromTargetFuncDefinition(Src),
@@ -2102,15 +2111,15 @@
IrrelevantAssignmentsAndInitializations) {
static constexpr llvm::StringRef Src = R"cc(
struct S {
- S(int* i);
+ S(int* I);
};
- void target(int* p) {
+ void target(int* P) {
// We don't collect if types on either side are not a supported pointer
// type.
- int a = 4;
- bool b = false;
- S e = p;
+ int A = 4;
+ bool B = false;
+ S AnS = P;
}
)cc";
EXPECT_THAT(
@@ -2123,16 +2132,16 @@
TEST(CollectEvidenceFromDefinitionTest, Arithmetic) {
static constexpr llvm::StringRef Src = R"cc(
- void target(int* a, int* b, int* c, int* d, int* e, int* f, int* g,
- int* h) {
- a += 1;
- b -= 2;
- c + 3;
- d - 4;
- e++;
- ++f;
- g--;
- --h;
+ void target(int* A, int* B, int* C, int* D, int* E, int* F, int* G,
+ int* H) {
+ A += 1;
+ B -= 2;
+ C + 3;
+ D - 4;
+ E++;
+ ++F;
+ G--;
+ --H;
}
)cc";
EXPECT_THAT(
@@ -2377,26 +2386,26 @@
TEST(CollectEvidenceFromDefinitionTest, LocalVariable) {
static constexpr llvm::StringRef Src = R"cc(
void target() {
- int* p = nullptr;
+ int* P = nullptr;
}
)cc";
EXPECT_THAT(
collectFromTargetFuncDefinition(Src),
UnorderedElementsAre(evidence(Slot(0), Evidence::ASSIGNED_FROM_NULLABLE,
- localVarNamed("p"))));
+ localVarNamed("P"))));
}
TEST(CollectEvidenceFromDefinitionTest, FunctionCallInLoop) {
static constexpr llvm::StringRef Src = R"cc(
- void target(int* p) {
- for (int i = 0; i < 3; ++i) {
+ void target(int* P) {
+ for (int I = 0; I < 3; ++I) {
target(nullptr);
}
- for (int i = 0; i < 3; ++i) {
- target(&i);
+ for (int I = 0; I < 3; ++I) {
+ target(&I);
}
- for (int i = 0; i < 3; ++i) {
- target(p);
+ for (int I = 0; I < 3; ++I) {
+ target(P);
}
}
)cc";
@@ -2409,10 +2418,10 @@
TEST(CollectEvidenceFromDefinitionTest, OutputParameterPointerToPointer) {
static constexpr llvm::StringRef Src = R"cc(
- void maybeModifyPtr(int** a);
- void target(int* p) {
- maybeModifyPtr(&p);
- *p;
+ void maybeModifyPtr(int** A);
+ void target(int* P) {
+ maybeModifyPtr(&P);
+ *P;
}
)cc";
EXPECT_THAT(collectFromTargetFuncDefinition(Src),
@@ -2421,10 +2430,10 @@
TEST(CollectEvidenceFromDefinitionTest, OutputParameterReferenceToPointer) {
static constexpr llvm::StringRef Src = R"cc(
- void maybeModifyPtr(int*& a);
- void target(int* p) {
- maybeModifyPtr(p);
- *p;
+ void maybeModifyPtr(int*& A);
+ void target(int* P) {
+ maybeModifyPtr(P);
+ *P;
}
)cc";
EXPECT_THAT(collectFromTargetFuncDefinition(Src),
@@ -2434,10 +2443,10 @@
TEST(CollectEvidenceFromDefinitionTest,
OutputParameterReferenceToConstPointer) {
static constexpr llvm::StringRef Src = R"cc(
- void dontModifyPtr(int* const& a);
- void target(int* p) {
- dontModifyPtr(p);
- *p;
+ void dontModifyPtr(int* const& A);
+ void target(int* P) {
+ dontModifyPtr(P);
+ *P;
}
)cc";
EXPECT_THAT(collectFromTargetFuncDefinition(Src),
@@ -2448,11 +2457,11 @@
TEST(CollectEvidenceFromDefinitionTest,
OutputParameterReferenceToPointerToPointer) {
static constexpr llvm::StringRef Src = R"cc(
- void maybeModifyPtr(int**& a);
- void target(int** p) {
- maybeModifyPtr(p);
- *p;
- **p;
+ void maybeModifyPtr(int**& A);
+ void target(int** P) {
+ maybeModifyPtr(P);
+ *P;
+ **P;
}
)cc";
EXPECT_THAT(collectFromTargetFuncDefinition(Src),
@@ -2461,10 +2470,10 @@
TEST(CollectEvidenceFromDefinitionTest, OutputParameterPointerToConstPointer) {
static constexpr llvm::StringRef Src = R"cc(
- void dontModifyPtr(int* const* a);
- void target(int* p) {
- dontModifyPtr(&p);
- *p;
+ void dontModifyPtr(int* const* A);
+ void target(int* P) {
+ dontModifyPtr(&P);
+ *P;
}
)cc";
EXPECT_THAT(collectFromTargetFuncDefinition(Src),
@@ -2476,10 +2485,10 @@
OutputParameterConstPointerToPointerToConst) {
static constexpr llvm::StringRef Src = R"cc(
// Outer pointer and int are const, but inner pointer can still be modified.
- void maybeModifyPtr(const int** const a);
- void target(const int* p) {
- maybeModifyPtr(&p);
- *p;
+ void maybeModifyPtr(const int** const A);
+ void target(const int* P) {
+ maybeModifyPtr(&P);
+ *P;
}
)cc";
EXPECT_THAT(collectFromTargetFuncDefinition(Src),
@@ -2488,12 +2497,12 @@
TEST(CollectEvidenceFromDefinitionTest, PassAsOutputParameterOrDereference) {
static constexpr llvm::StringRef Src = R"cc(
- void maybeModifyPtr(int** a);
- void target(int* p, bool b) {
- if (b) {
- maybeModifyPtr(&p);
+ void maybeModifyPtr(int** A);
+ void target(int* P, bool B) {
+ if (B) {
+ maybeModifyPtr(&P);
} else {
- *p;
+ *P;
}
}
)cc";
@@ -2505,12 +2514,12 @@
TEST(CollectEvidenceFromDefinitionTest,
ConditionallyPassAsOutputParameterAlwaysDereference) {
static constexpr llvm::StringRef Src = R"cc(
- void maybeModifyPtr(int** a);
- void target(int* p, bool b) {
- if (b) maybeModifyPtr(&p);
- *p; // Because we model p as Unknown post-output-parameter-use, adding an
+ void maybeModifyPtr(int** A);
+ void target(int* P, bool B) {
+ if (B) maybeModifyPtr(&P);
+ *P; // Because we model P as Unknown post-output-parameter-use, adding an
// annotation would not be considered sufficient to make this
- // dereference safe, so we do not collect evidence for p.
+ // dereference safe, so we do not collect evidence for P.
}
)cc";
EXPECT_THAT(collectFromTargetFuncDefinition(Src),
@@ -2519,22 +2528,22 @@
TEST(CollectEvidenceFromDefinitionTest, FromGlobalLabmdaBodyForGlobal) {
static constexpr llvm::StringRef Src = R"cc(
- int* p;
- auto Lambda = []() { *p; };
+ int* P;
+ auto Lambda = []() { *P; };
)cc";
EXPECT_THAT(
collectFromDefinitionNamed("operator()", Src),
UnorderedElementsAre(evidence(Slot(0), Evidence::UNCHECKED_DEREFERENCE,
- globalVarNamed("p"))));
+ globalVarNamed("P"))));
}
// TODO(b/315967534) Collect for captured function parameters, specifically from
// the unchecked dereference of `foo`'s parameter.
TEST(CollectEvidenceFromDefinitionTest, FromLocalLambdaForCapturedParam) {
static constexpr llvm::StringRef Src = R"cc(
- void foo(int* p) {
- auto Lambda = [&p]() { *p; };
+ void foo(int* P) {
+ auto Lambda = [&P]() { *P; };
}
)cc";
@@ -2557,8 +2566,8 @@
TEST(CollectEvidenceFromDefinitionTest, ForLambdaParamOrReturn) {
static constexpr llvm::StringRef Src = R"cc(
- auto Lambda = [](int* p) -> int* {
- *p;
+ auto Lambda = [](int* P) -> int* {
+ *P;
return nullptr;
};
)cc";
@@ -2615,29 +2624,29 @@
#include <memory>
#include <utility>
struct MyStruct {
- std::unique_ptr<int> p;
- Nonnull<std::unique_ptr<int>> q;
- std::unique_ptr<int> r;
+ std::unique_ptr<int> P;
+ Nonnull<std::unique_ptr<int>> Q;
+ std::unique_ptr<int> R;
};
- void target(Nullable<std::unique_ptr<int>> a, std::unique_ptr<int> b) {
- MyStruct{std::move(a), std::move(b), nullptr};
+ void target(Nullable<std::unique_ptr<int>> A, std::unique_ptr<int> B) {
+ MyStruct{std::move(A), std::move(B), nullptr};
}
)cc";
EXPECT_THAT(
collectFromTargetFuncDefinition(Src),
UnorderedElementsAre(evidence(Slot(0), Evidence::ASSIGNED_FROM_NULLABLE,
- fieldNamed("MyStruct::p")),
+ fieldNamed("MyStruct::P")),
evidence(paramSlot(1), Evidence::ASSIGNED_TO_NONNULL,
functionNamed("target")),
evidence(Slot(0), Evidence::ASSIGNED_FROM_NULLABLE,
- fieldNamed("MyStruct::r"))));
+ fieldNamed("MyStruct::R"))));
}
// This is a crash repro related to aggregate initialization.
TEST(CollectEvidenceFromDefinitionTest, NonRecordInitListExpr) {
static constexpr llvm::StringRef Src = R"cc(
- void target() { int a[3] = {}; }
+ void target() { int A[3] = {}; }
)cc";
EXPECT_THAT(collectFromTargetFuncDefinition(Src), IsEmpty());
}
@@ -2648,7 +2657,7 @@
#include <memory>
void foo(int*);
- void target(Nullable<std::unique_ptr<int>> p) { foo(p.get()); }
+ void target(Nullable<std::unique_ptr<int>> P) { foo(P.get()); }
)cc";
EXPECT_THAT(collectFromTargetFuncDefinition(Src),
Contains(evidence(paramSlot(0), Evidence::NULLABLE_ARGUMENT,
@@ -2660,7 +2669,7 @@
TEST(CollectEvidenceFromDefinitionTest, TransparentInitListExpr) {
static constexpr llvm::StringRef Src = R"cc(
struct S {};
- void foo(S p) {}
+ void foo(S P) {}
S get();
void target() { foo({get()}); }
@@ -2678,8 +2687,8 @@
struct Derived : public Base {
int* foo() override {
- static int i;
- return &i;
+ static int I;
+ return &I;
}
};
@@ -2724,17 +2733,17 @@
TEST(CollectEvidenceFromDefinitionTest, FromVirtualDerivedForParamNonnull) {
static constexpr llvm::StringRef Src = R"cc(
struct Base {
- virtual void foo(int* p);
+ virtual void foo(int* P);
};
struct Derived : public Base {
- void foo(int* p) override { *p; }
+ void foo(int* P) override { *P; }
};
void target() {
- int i;
+ int I;
Derived D;
- D.foo(&i);
+ D.foo(&I);
}
)cc";
EXPECT_THAT(
@@ -2757,11 +2766,11 @@
TEST(CollectEvidenceFromDefinitionTest, FromVirtualDerivedForParamNullable) {
static constexpr llvm::StringRef Src = R"cc(
struct Base {
- virtual void foo(int* p);
+ virtual void foo(int* P);
};
struct Derived : public Base {
- void foo(int* p) override { p = nullptr; }
+ void foo(int* P) override { P = nullptr; }
};
void target() {
@@ -2784,8 +2793,8 @@
static constexpr llvm::StringRef Src = R"cc(
struct Base {
virtual int* foo() {
- static int i;
- return &i;
+ static int I;
+ return &I;
}
};
@@ -2840,17 +2849,17 @@
TEST(CollectEvidenceFromDefinitionTest, FromVirtualBaseForParamNonnull) {
static constexpr llvm::StringRef Src = R"cc(
struct Base {
- virtual void foo(int* p) { *p; }
+ virtual void foo(int* P) { *P; }
};
struct Derived : public Base {
- void foo(int* p) override;
+ void foo(int* P) override;
};
void target() {
- int i;
+ int I;
Base B;
- B.foo(&i);
+ B.foo(&I);
}
)cc";
EXPECT_THAT(
@@ -2867,11 +2876,11 @@
TEST(CollectEvidenceFromDefinitionTest, FromVirtualBaseForParamNullable) {
static constexpr llvm::StringRef Src = R"cc(
struct Base {
- virtual void foo(int* p) { p = nullptr; }
+ virtual void foo(int* P) { P = nullptr; }
};
struct Derived : public Base {
- void foo(int* p) override;
+ void foo(int* P) override;
};
void target() {
@@ -2922,7 +2931,7 @@
TEST(CollectEvidenceFromDefinitionTest, FromVirtualBaseMultipleLayers) {
static constexpr llvm::StringRef Src = R"cc(
struct Base {
- virtual void foo(int* p) { p = nullptr; }
+ virtual void foo(int* P) { P = nullptr; }
};
struct Derived : public Base {
@@ -2946,12 +2955,12 @@
TEST(CollectEvidenceFromDefinitionTest, NotInferenceTarget) {
static constexpr llvm::StringRef Src = R"cc(
- void isATarget(Nonnull<int*> a);
+ void isATarget(Nonnull<int*> A);
template <typename T>
- T* target(T* p) {
- *p;
- Nonnull<int*> a = p;
- isATarget(p);
+ T* target(T* P) {
+ *P;
+ Nonnull<int*> A = P;
+ isATarget(P);
target<T>(nullptr);
target<int>(nullptr);
return nullptr;
@@ -2970,13 +2979,13 @@
TEST(CollectEvidenceFromDefinitionTest, PropagatesPreviousInferences) {
static constexpr llvm::StringRef Src = R"cc(
- void calledWithToBeNullable(int* x);
- void calledWithToBeNonnull(int* a);
- void target(int* p, int* q) {
- target(nullptr, q);
- calledWithToBeNullable(p);
- *q;
- calledWithToBeNonnull(q);
+ void calledWithToBeNullable(int* X);
+ void calledWithToBeNonnull(int* A);
+ void target(int* P, int* Q) {
+ target(nullptr, Q);
+ calledWithToBeNullable(P);
+ *Q;
+ calledWithToBeNonnull(Q);
}
)cc";
std::string TargetUsr = "c:@F@target#*I#S0_#";
@@ -3015,12 +3024,12 @@
TEST(CollectEvidenceFromDefinitionTest,
AnalysisUsesPreviousInferencesForSlotsOutsideTargetDefinition) {
static constexpr llvm::StringRef Src = R"cc(
- int* returnsToBeNonnull(int* a) {
- return a;
+ int* returnsToBeNonnull(int* A) {
+ return A;
}
- int* target(int* q) {
- *q;
- return returnsToBeNonnull(q);
+ int* target(int* Q) {
+ *Q;
+ return returnsToBeNonnull(Q);
}
)cc";
std::string TargetUsr = "c:@F@target#*I#";
@@ -3101,12 +3110,12 @@
TEST(CollectEvidenceFromDefinitionTest,
PreviousInferencesOfNonTargetParameterNullabilitiesPropagate) {
static constexpr llvm::StringRef Src = R"cc(
- void takesToBeNonnull(int* a) {
+ void takesToBeNonnull(int* A) {
// Not read when collecting evidence only from Target, but corresponding
// inference is explicitly input below.
- *a;
+ *A;
}
- void target(int* q) { takesToBeNonnull(q); }
+ void target(int* Q) { takesToBeNonnull(Q); }
)cc";
std::string TakesToBeNonnullUsr = "c:@F@takesToBeNonnull#*I#";
@@ -3124,8 +3133,8 @@
TEST(CollectEvidenceFromDefinitionTest, Pragma) {
static constexpr llvm::StringRef Src = R"cc(
#pragma nullability file_default nonnull
- int* target(NullabilityUnknown<int*> p) {
- return p;
+ int* target(NullabilityUnknown<int*> P) {
+ return P;
}
)cc";
EXPECT_THAT(collectFromTargetFuncDefinition(Src),
@@ -3136,8 +3145,8 @@
TEST(CollectEvidenceFromDefinitionTest, PragmaLocalTopLevelPointer) {
static constexpr llvm::StringRef Src = R"cc(
#pragma nullability file_default nonnull
- void target(NullabilityUnknown<int*> p) {
- int* local_top_level_pointer = p;
+ void target(NullabilityUnknown<int*> P) {
+ int* local_top_level_pointer = P;
}
)cc";
EXPECT_THAT(collectFromTargetFuncDefinition(Src),
@@ -3149,9 +3158,9 @@
TEST(CollectEvidenceFromDefinitionTest, PragmaAndMacroReplace) {
llvm::Twine Src = CheckMacroDefinitions + R"cc(
#pragma nullability file_default nonnull
- int* target(NullabilityUnknown<int*> p) {
- CHECK(p);
- return p;
+ int* target(NullabilityUnknown<int*> P) {
+ CHECK(P);
+ return P;
}
)cc";
EXPECT_THAT(collectFromTargetFuncDefinition(Src.str()),
@@ -3162,9 +3171,9 @@
TEST(CollectEvidenceFromDefinitionTest, SolverLimitReached) {
static constexpr llvm::StringRef Src = R"cc(
- void target(int* p, int* q) {
- *p;
- *q;
+ void target(int* P, int* Q) {
+ *P;
+ *Q;
}
)cc";
NullabilityPragmas Pragmas;
@@ -3189,55 +3198,55 @@
TEST(CollectEvidenceFromDeclarationTest, GlobalVariable) {
llvm::StringLiteral Src = R"cc(
- Nullable<int *> target;
+ Nullable<int *> Target;
)cc";
- EXPECT_THAT(collectFromTargetDecl(Src),
+ EXPECT_THAT(collectFromTargetVarDecl(Src),
ElementsAre(evidence(Slot(0), Evidence::ANNOTATED_NULLABLE,
- globalVarNamed("target"))));
+ globalVarNamed("Target"))));
}
TEST(SmartPointerCollectEvidenceFromDeclarationTest, GlobalVariable) {
llvm::StringLiteral Src = R"cc(
#include <memory>
- Nullable<std::unique_ptr<int>> target;
+ Nullable<std::unique_ptr<int>> Target;
)cc";
- EXPECT_THAT(collectFromTargetDecl(Src),
+ EXPECT_THAT(collectFromTargetVarDecl(Src),
ElementsAre(evidence(Slot(0), Evidence::ANNOTATED_NULLABLE,
- globalVarNamed("target"))));
+ globalVarNamed("Target"))));
}
TEST(CollectEvidenceFromDeclarationTest, StaticMemberVariable) {
llvm::StringLiteral Src = R"cc(
struct S {
- static Nonnull<int*> target;
+ static Nonnull<int*> Target;
};
)cc";
- EXPECT_THAT(collectFromTargetDecl(Src),
+ EXPECT_THAT(collectFromTargetVarDecl(Src),
ElementsAre(evidence(Slot(0), Evidence::ANNOTATED_NONNULL,
- staticFieldNamed("S::target"))));
+ staticFieldNamed("S::Target"))));
}
TEST(CollectEvidenceFromDeclarationTest, Field) {
llvm::StringLiteral Src = R"cc(
struct S {
- Nonnull<int*> target;
+ Nonnull<int*> Target;
};
)cc";
- EXPECT_THAT(collectFromTargetDecl(Src),
+ EXPECT_THAT(collectFromTargetVarDecl(Src),
ElementsAre(evidence(Slot(0), Evidence::ANNOTATED_NONNULL,
- fieldNamed("S::target"))));
+ fieldNamed("S::Target"))));
}
TEST(SmartPointerCollectEvidenceFromDeclarationTest, Field) {
llvm::StringLiteral Src = R"cc(
#include <memory>
struct S {
- Nonnull<std::unique_ptr<int>> target;
+ Nonnull<std::unique_ptr<int>> Target;
};
)cc";
- EXPECT_THAT(collectFromTargetDecl(Src),
+ EXPECT_THAT(collectFromTargetVarDecl(Src),
ElementsAre(evidence(Slot(0), Evidence::ANNOTATED_NONNULL,
- fieldNamed("S::target"))));
+ fieldNamed("S::Target"))));
}
TEST(CollectEvidenceFromDeclarationTest, FunctionDeclReturnType) {
@@ -3245,7 +3254,7 @@
Nonnull<int *> target();
)cc";
EXPECT_THAT(
- collectFromTargetDecl(Src),
+ collectFromTargetFuncDecl(Src),
ElementsAre(evidence(SLOT_RETURN_TYPE, Evidence::ANNOTATED_NONNULL)));
}
@@ -3253,7 +3262,7 @@
llvm::StringLiteral Src = R"cc(
void target(Nullable<int*>, int*, Nonnull<int*>);
)cc";
- EXPECT_THAT(collectFromTargetDecl(Src),
+ EXPECT_THAT(collectFromTargetFuncDecl(Src),
ElementsAre(evidence(paramSlot(0), Evidence::ANNOTATED_NULLABLE),
evidence(paramSlot(2), Evidence::ANNOTATED_NONNULL)));
}
@@ -3262,7 +3271,7 @@
llvm::StringLiteral Src = R"cc(
Nonnull<int*>** target(Nullable<int*>*);
)cc";
- EXPECT_THAT(collectFromTargetDecl(Src), IsEmpty());
+ EXPECT_THAT(collectFromTargetFuncDecl(Src), IsEmpty());
}
TEST(SmartPointerCollectEvidenceFromDeclarationTest, FunctionDecl) {
@@ -3272,7 +3281,7 @@
Nullable<std::unique_ptr<int>>);
)cc";
EXPECT_THAT(
- collectFromTargetDecl(Src),
+ collectFromTargetFuncDecl(Src),
ElementsAre(evidence(SLOT_RETURN_TYPE, Evidence::ANNOTATED_NULLABLE),
evidence(paramSlot(0), Evidence::ANNOTATED_NONNULL),
evidence(paramSlot(1), Evidence::ANNOTATED_NULLABLE)));
@@ -3287,14 +3296,14 @@
static void target(const S<B>&) {}
};
)cc";
- EXPECT_THAT(collectFromTargetDecl(Src), IsEmpty());
+ EXPECT_THAT(collectFromTargetFuncDecl(Src), IsEmpty());
}
TEST(CollectEvidenceFromDeclarationTest, DefaultArgumentNullptrLiteral) {
static constexpr llvm::StringRef Src = R"cc(
void target(int* = nullptr);
)cc";
- EXPECT_THAT(collectFromTargetDecl(Src),
+ EXPECT_THAT(collectFromTargetFuncDecl(Src),
UnorderedElementsAre(
evidence(paramSlot(0), Evidence::NULLABLE_ARGUMENT)));
}
@@ -3303,18 +3312,18 @@
static constexpr llvm::StringRef Src = R"cc(
void target(int* = 0);
)cc";
- EXPECT_THAT(collectFromTargetDecl(Src),
+ EXPECT_THAT(collectFromTargetFuncDecl(Src),
UnorderedElementsAre(
evidence(paramSlot(0), Evidence::NULLABLE_ARGUMENT)));
}
TEST(CollectEvidenceFromDeclarationTest, DefaultArgumentAnnotatedVariable) {
static constexpr llvm::StringRef Src = R"cc(
- Nonnull<int*> q;
- void target(int* = q);
+ Nonnull<int*> Q;
+ void target(int* = Q);
)cc";
EXPECT_THAT(
- collectFromTargetDecl(Src),
+ collectFromTargetFuncDecl(Src),
UnorderedElementsAre(evidence(paramSlot(0), Evidence::NONNULL_ARGUMENT)));
}
@@ -3325,7 +3334,7 @@
void target(int* = getDefault());
)cc";
EXPECT_THAT(
- collectFromTargetDecl(Src),
+ collectFromTargetFuncDecl(Src),
UnorderedElementsAre(evidence(paramSlot(0), Evidence::NULLABLE_ARGUMENT,
functionNamed("target"))));
}
@@ -3334,12 +3343,12 @@
DefaultArgumentUnannotatedNonLiteralExpressionsUnknown) {
static constexpr llvm::StringRef Src = R"cc(
int* getDefault();
- int* q = nullptr;
- int i = 1;
- void target(int* = getDefault(), int* = q, int* = &i);
+ int* Q = nullptr;
+ int I = 1;
+ void target(int* = getDefault(), int* = Q, int* = &I);
)cc";
EXPECT_THAT(
- collectFromTargetDecl(Src),
+ collectFromTargetFuncDecl(Src),
UnorderedElementsAre(evidence(paramSlot(0), Evidence::UNKNOWN_ARGUMENT,
functionNamed("target")),
evidence(paramSlot(1), Evidence::UNKNOWN_ARGUMENT,
@@ -3355,7 +3364,7 @@
void target(std::unique_ptr<int> = nullptr);
)cc";
EXPECT_THAT(
- collectFromTargetDecl(Src),
+ collectFromTargetFuncDecl(Src),
UnorderedElementsAre(evidence(paramSlot(0), Evidence::NULLABLE_ARGUMENT,
functionNamed("target"))));
}
@@ -3367,7 +3376,7 @@
void target(std::unique_ptr<int> = std::make_unique<int>(1));
)cc";
EXPECT_THAT(
- collectFromTargetDecl(Src),
+ collectFromTargetFuncDecl(Src),
UnorderedElementsAre(evidence(paramSlot(0), Evidence::UNKNOWN_ARGUMENT,
functionNamed("target"))));
}
@@ -3376,11 +3385,11 @@
DefaultArgumentReferenceTypesNullptrLiteral) {
static constexpr llvm::StringRef Src = R"cc(
#include <memory>
- void target(const std::unique_ptr<int>& pl = nullptr,
- std::unique_ptr<int>&& pr = nullptr);
+ void target(const std::unique_ptr<int>& PL = nullptr,
+ std::unique_ptr<int>&& PR = nullptr);
)cc";
EXPECT_THAT(
- collectFromTargetDecl(Src),
+ collectFromTargetFuncDecl(Src),
UnorderedElementsAre(evidence(paramSlot(0), Evidence::NULLABLE_ARGUMENT,
functionNamed("target")),
evidence(paramSlot(1), Evidence::NULLABLE_ARGUMENT,
@@ -3389,10 +3398,10 @@
TEST(CollectEvidenceFromDeclarationTest, NonnullAttributeOnFunction) {
static constexpr llvm::StringRef Src = R"cc(
- int* target(int* p, int** q, int*& r, bool b) __attribute__((nonnull));
+ int* target(int* P, int** Q, int*& R, bool B) __attribute__((nonnull));
)cc";
EXPECT_THAT(
- collectFromTargetDecl(Src),
+ collectFromTargetFuncDecl(Src),
// attribute applies to top-level non-reference raw pointer
// parameter types only, not return type or other params.
ElementsAre(evidence(paramSlot(0), Evidence::GCC_NONNULL_ATTRIBUTE),
@@ -3401,11 +3410,11 @@
TEST(CollectEvidenceFromDeclarationTest, NonnullAttributeOnFunctionWithArgs) {
static constexpr llvm::StringRef Src = R"cc(
- int* target(int* p, int** q, int*& r, bool b, int* not_indicated)
+ int* target(int* P, int** Q, int*& R, bool B, int* NotIndicated)
__attribute__((nonnull(1, 2, 3, 4)));
)cc";
EXPECT_THAT(
- collectFromTargetDecl(Src),
+ collectFromTargetFuncDecl(Src),
// attribute applies to the indicated and eligible parameters only.
ElementsAre(evidence(paramSlot(0), Evidence::GCC_NONNULL_ATTRIBUTE),
evidence(paramSlot(1), Evidence::GCC_NONNULL_ATTRIBUTE)));
@@ -3415,11 +3424,11 @@
static constexpr llvm::StringRef Src = R"cc(
struct T {
// Index 1 on a non-static method is for the implicit `this` parameter.
- int* target(int* p, int* not_indicated) __attribute__((nonnull(2)));
+ int* target(int* P, int* NotIndicated) __attribute__((nonnull(2)));
};
)cc";
EXPECT_THAT(
- collectFromTargetDecl(Src),
+ collectFromTargetFuncDecl(Src),
ElementsAre(evidence(paramSlot(0), Evidence::GCC_NONNULL_ATTRIBUTE)));
}
@@ -3428,20 +3437,20 @@
static constexpr llvm::StringRef Src = R"cc(
struct T {
// no implicit `this` parameter for static methods.
- static int* target(int* p, int* q) __attribute__((nonnull(2)));
+ static int* target(int* P, int* Q) __attribute__((nonnull(2)));
};
)cc";
EXPECT_THAT(
- collectFromTargetDecl(Src),
+ collectFromTargetFuncDecl(Src),
ElementsAre(evidence(paramSlot(1), Evidence::GCC_NONNULL_ATTRIBUTE)));
}
TEST(CollectEvidenceFromDeclarationTest, NonnullAttributeOnParam) {
static constexpr llvm::StringRef Src = R"cc(
- int* target(int* p __attribute__((nonnull())), int* not_indicated);
+ int* target(int* P __attribute__((nonnull())), int* NotIndicated);
)cc";
EXPECT_THAT(
- collectFromTargetDecl(Src),
+ collectFromTargetFuncDecl(Src),
ElementsAre(evidence(paramSlot(0), Evidence::GCC_NONNULL_ATTRIBUTE)));
}
@@ -3449,11 +3458,11 @@
NonnullAttributeOnFunction) {
static constexpr llvm::StringRef Src = R"cc(
#include <memory>
- void target(std::unique_ptr<int> p, std::unique_ptr<int>* q,
- std::unique_ptr<int*> r) __attribute__((nonnull));
+ void target(std::unique_ptr<int> P, std::unique_ptr<int>* Q,
+ std::unique_ptr<int*> R) __attribute__((nonnull));
)cc";
EXPECT_THAT(
- collectFromTargetDecl(Src),
+ collectFromTargetFuncDecl(Src),
// attribute applies to top-level non-reference *raw* pointer
// parameter types only.
ElementsAre(evidence(paramSlot(1), Evidence::GCC_NONNULL_ATTRIBUTE)));
@@ -3464,7 +3473,7 @@
int** target() __attribute__((returns_nonnull));
)cc";
EXPECT_THAT(
- collectFromTargetDecl(Src),
+ collectFromTargetFuncDecl(Src),
// Affects the top-level pointer.
ElementsAre(evidence(SLOT_RETURN_TYPE, Evidence::GCC_NONNULL_ATTRIBUTE)));
}
@@ -3474,7 +3483,7 @@
int*& target() __attribute__((returns_nonnull));
)cc";
// No effect on reference types.
- EXPECT_THAT(collectFromTargetDecl(Src), IsEmpty());
+ EXPECT_THAT(collectFromTargetFuncDecl(Src), IsEmpty());
}
TEST(SmartPointerCollectEvidenceFromDeclarationTest, ReturnsNonnullAttribute) {
@@ -3483,15 +3492,15 @@
std::unique_ptr<int> target() __attribute__((returns_nonnull));
)cc";
// No effect on smart pointers.
- EXPECT_THAT(collectFromTargetDecl(Src), IsEmpty());
+ EXPECT_THAT(collectFromTargetFuncDecl(Src), IsEmpty());
}
TEST(CollectEvidenceFromDeclarationTest, Pragma) {
static constexpr llvm::StringRef Src = R"cc(
#pragma nullability file_default nonnull
- void target(int* p);
+ void target(int* P);
)cc";
- EXPECT_THAT(collectFromTargetDecl(Src),
+ EXPECT_THAT(collectFromTargetFuncDecl(Src),
UnorderedElementsAre(
evidence(paramSlot(0), Evidence::ANNOTATED_NONNULL)));
}
@@ -3522,17 +3531,17 @@
};
return std::make_unique<Action>(Pragmas);
};
- Inputs.Code = R"cpp(
+ Inputs.Code = R"cc(
#include "input.h"
#include "header.h"
int* foo();
- )cpp";
- Inputs.ExtraFiles["input.h"] = R"cpp(
+ )cc";
+ Inputs.ExtraFiles["input.h"] = R"cc(
int* bar();
- )cpp";
- Inputs.ExtraFiles["header.h"] = R"cpp(
+ )cc";
+ Inputs.ExtraFiles["header.h"] = R"cc(
int* baz();
- )cpp";
+ )cc";
TestAST AST(Inputs);
auto Sites = EvidenceSites::discover(AST.context(),
@@ -3596,46 +3605,46 @@
TestAST AST = getAugmentedTestInputs(
R"cc(
#include <memory>
- int* x = true ? nullptr : nullptr;
- int* y;
- int a;
- int b = *y;
- std::unique_ptr<int> p;
- std::unique_ptr<int> q = nullptr;
+ int* X = true ? nullptr : nullptr;
+ int* Y;
+ int A;
+ int B = *Y;
+ std::unique_ptr<int> P;
+ std::unique_ptr<int> Q = nullptr;
)cc",
Pragmas);
auto Sites = EvidenceSites::discover(AST.context());
EXPECT_THAT(Sites.Declarations,
- UnorderedElementsAre(declNamed("x"), declNamed("y"),
- declNamed("p"), declNamed("q")));
+ UnorderedElementsAre(declNamed("X"), declNamed("Y"),
+ declNamed("P"), declNamed("Q")));
EXPECT_THAT(
Sites.Definitions,
UnorderedElementsAre(
- declNamed("x"), declNamed("b"),
- // unique_ptr p has an initializer because of default construction.
- declNamed("p"), declNamed("q")));
+ declNamed("X"), declNamed("B"),
+ // unique_ptr P has an initializer because of default construction.
+ declNamed("P"), declNamed("Q")));
}
TEST(EvidenceSitesTest, StaticMemberVariables) {
TestAST AST(R"cc(
struct S {
- inline static int* a = nullptr;
- static int* b;
- static int* c;
+ inline static int* A = nullptr;
+ static int* B;
+ static int* C;
};
- int* S::c = nullptr;
+ int* S::C = nullptr;
)cc");
auto Sites = EvidenceSites::discover(AST.context());
EXPECT_THAT(
Sites.Declarations,
UnorderedElementsAre(
- declNamed("S::a"), declNamed("S::b"),
+ declNamed("S::A"), declNamed("S::B"),
// one for in-class declaration and one for out-of-class definition
- declNamed("S::c"), declNamed("S::c")));
+ declNamed("S::C"), declNamed("S::C")));
EXPECT_THAT(Sites.Definitions,
- UnorderedElementsAre(declNamed("S::a"), declNamed("S::c")));
+ UnorderedElementsAre(declNamed("S::A"), declNamed("S::C")));
}
TEST(EvidenceSitesTest, NonStaticMemberVariables) {
@@ -3644,32 +3653,32 @@
R"cc(
#include <memory>
struct S {
- int* a = nullptr;
- int* b;
- std::unique_ptr<int> p = nullptr;
- std::unique_ptr<int> q;
+ int* A = nullptr;
+ int* B;
+ std::unique_ptr<int> P = nullptr;
+ std::unique_ptr<int> Q;
};
)cc",
Pragmas);
auto Sites = EvidenceSites::discover(AST.context());
EXPECT_THAT(Sites.Declarations,
- UnorderedElementsAre(declNamed("S::a"), declNamed("S::b"),
- declNamed("S::p"), declNamed("S::q")));
+ UnorderedElementsAre(declNamed("S::A"), declNamed("S::B"),
+ declNamed("S::P"), declNamed("S::Q")));
EXPECT_THAT(Sites.Definitions, IsEmpty());
}
TEST(EvidenceSitesTest, LocalVariables) {
TestAST AST(R"cc(
void foo() {
- int* p = nullptr;
- static int* q = nullptr;
- static int* r;
+ int* P = nullptr;
+ static int* Q = nullptr;
+ static int* R;
}
)cc");
auto Sites = EvidenceSites::discover(AST.context());
EXPECT_THAT(
Sites.Declarations,
- UnorderedElementsAre(declNamed("p"), declNamed("q"), declNamed("r")));
+ UnorderedElementsAre(declNamed("P"), declNamed("Q"), declNamed("R")));
EXPECT_THAT(Sites.Definitions, UnorderedElementsAre(declNamed("foo")));
}
@@ -3697,22 +3706,22 @@
};
template <int I>
- int* v = nullptr;
+ int* V = nullptr;
template <>
- int* v<1> = nullptr;
+ int* V<1> = nullptr;
- int Unused = f<0>(v<0>) + f<1>(v<1>) + S{}.f<0>(nullptr) + T<0>{}.f(nullptr);
+ int Unused = f<0>(V<0>) + f<1>(V<1>) + S{}.f<0>(nullptr) + T<0>{}.f(nullptr);
)cc");
auto Sites = EvidenceSites::discover(AST.context());
// Relevant declarations are the written ones that are not templates.
EXPECT_THAT(Sites.Declarations,
- UnorderedElementsAre(declNamed("f<1>"), declNamed("v<1>")));
+ UnorderedElementsAre(declNamed("f<1>"), declNamed("V<1>")));
// Instantiations are relevant definitions, as is the global variable Unused.
EXPECT_THAT(Sites.Definitions,
- UnorderedElementsAre(declNamed("f<0>"), declNamed("v<0>"),
- declNamed("f<1>"), declNamed("v<1>"),
+ UnorderedElementsAre(declNamed("f<0>"), declNamed("V<0>"),
+ declNamed("f<1>"), declNamed("V<1>"),
declNamed("S::f<0>"), declNamed("T<0>::f"),
declNamed("Unused")));
}
diff --git a/nullability/inference/eligible_ranges_test.cc b/nullability/inference/eligible_ranges_test.cc
index 927f19c..467fa58 100644
--- a/nullability/inference/eligible_ranges_test.cc
+++ b/nullability/inference/eligible_ranges_test.cc
@@ -102,18 +102,18 @@
}
std::optional<clang::tidy::nullability::TypeLocRanges> getFieldRanges(
- llvm::StringRef Input, llvm::StringRef FieldName = "target") {
+ llvm::StringRef Input, llvm::StringRef FieldName = "Target") {
return getRanges<FieldDecl>(
Input, FieldName.empty() ? fieldDecl() : fieldDecl(hasName(FieldName)));
}
std::optional<clang::tidy::nullability::TypeLocRanges> getVarRanges(
- llvm::StringRef Input, llvm::StringRef VarName = "target") {
+ llvm::StringRef Input, llvm::StringRef VarName = "Target") {
return getRanges<VarDecl>(Input, varDecl(hasName(VarName)));
}
TEST(EligibleRangesTest, ReturnAndOneParameterIdentified) {
- auto Input = Annotations("$r[[int *]]target($p[[int *]]p) { return p; }");
+ auto Input = Annotations("$r[[int *]]target($p[[int *]]P) { return P; }");
EXPECT_THAT(
getFunctionRanges(Input.code()),
Optional(TypeLocRanges(
@@ -124,7 +124,7 @@
}
TEST(EligibleRangesTest, OnlyFirstParameterIdentified) {
- auto Input = Annotations("void target([[int *]]p1, int p2) { return; }");
+ auto Input = Annotations("void target([[int *]]P1, int P2) { return; }");
EXPECT_THAT(
getFunctionRanges(Input.code()),
Optional(TypeLocRanges(
@@ -133,7 +133,7 @@
// Checks that a function decl without a body is handled correctly.
TEST(EligibleRangesTest, DeclHandled) {
- auto Input = Annotations("void target([[int *]]p1, int p2);");
+ auto Input = Annotations("void target([[int *]]P1, int P2);");
EXPECT_THAT(
getFunctionRanges(Input.code()),
Optional(TypeLocRanges(
@@ -142,7 +142,7 @@
TEST(EligibleRangesTest, AllNestedPointersEligible) {
auto Input =
- Annotations("void target($three[[$two[[$one[[int *]]*]]*]]p1, int p2);");
+ Annotations("void target($three[[$two[[$one[[int *]]*]]*]]P1, int P2);");
EXPECT_THAT(getFunctionRanges(Input.code()),
Optional(TypeLocRanges(
MainFileName,
@@ -153,8 +153,8 @@
TEST(EligibleRangesTest, DeclConstExcluded) {
auto Input = Annotations(R"(
- void target($one[[int *]] const p1,
- $two_o[[$two_i[[int *]] const *]] const p2);
+ void target($one[[int *]] const P1,
+ $two_o[[$two_i[[int *]] const *]] const P2);
)");
EXPECT_THAT(getFunctionRanges(Input.code()),
Optional(TypeLocRanges(
@@ -166,7 +166,7 @@
TEST(EligibleRangesTest, PointeeConstIncluded) {
auto Input = Annotations(R"(
- void target([[const int *]]p);
+ void target([[const int *]]P);
)");
EXPECT_THAT(
getFunctionRanges(Input.code()),
@@ -175,7 +175,7 @@
}
TEST(EligibleRangesTest, NestedPointeeConstIncluded) {
- auto Input = Annotations("void target($o[[$i[[const int *]] const *]]p);");
+ auto Input = Annotations("void target($o[[$i[[const int *]] const *]]P);");
EXPECT_THAT(getFunctionRanges(Input.code()),
Optional(TypeLocRanges(
MainFileName,
@@ -185,9 +185,9 @@
TEST(EligibleRangesTest, AnnotatedSlotsGetRangesForPointerTypeOnly) {
auto Input = Annotations(R"(
- void target(Nonnull<$one[[int *]]> nonnull,
- Nullable<$two[[int *]]> nullable,
- NullabilityUnknown<$three[[int *]]> unknown);
+ void target(Nonnull<$one[[int *]]> NonnullP,
+ Nullable<$two[[int *]]> NullableP,
+ NullabilityUnknown<$three[[int *]]> UnknownP);
)");
EXPECT_THAT(
getFunctionRanges(Input.code()),
@@ -213,9 +213,9 @@
// Note also that these custom annotations are aliases for the nullability
// annotations, not themselves annotated. Aliases of any depth for a
// nullability annotation are considered an annotation.
- void target(custom::CustomNonnull<$one[[int *]]> nonnull,
- custom::CustomNullable<$two[[int *]]> nullable,
- custom::CustomUnknown<$three[[int *]]> unknown);
+ void target(custom::CustomNonnull<$one[[int *]]> NonnullP,
+ custom::CustomNullable<$two[[int *]]> NullableP,
+ custom::CustomUnknown<$three[[int *]]> UnknownP);
)");
EXPECT_THAT(getFunctionRanges(Input.code()),
Optional(TypeLocRanges(
@@ -226,7 +226,7 @@
}
TEST(EligibleRangesTest, NestedAnnotationsGetOneRange) {
- auto Input = Annotations(R"(void target(Nonnull<Nonnull<[[int *]]>> a);)");
+ auto Input = Annotations(R"(void target(Nonnull<Nonnull<[[int *]]>> P);)");
EXPECT_THAT(
getFunctionRanges(Input.code()),
Optional(TypeLocRanges(
@@ -240,10 +240,10 @@
class unique_ptr;
}
void target(
- Nonnull<$one_o[[$one_i[[int *]]*]]> p,
- Nonnull<$two_o[[std::unique_ptr<$two_i[[int*]]>]]> q,
- Nonnull<$three_o[[$three_i[[std::unique_ptr<int>]]*]]> r,
- Nonnull<$four_o[[std::unique_ptr<$four_i[[std::unique_ptr<int>]]>]]> s);
+ Nonnull<$one_o[[$one_i[[int *]]*]]> P,
+ Nonnull<$two_o[[std::unique_ptr<$two_i[[int*]]>]]> Q,
+ Nonnull<$three_o[[$three_i[[std::unique_ptr<int>]]*]]> R,
+ Nonnull<$four_o[[std::unique_ptr<$four_i[[std::unique_ptr<int>]]>]]> S);
)");
EXPECT_THAT(getFunctionRanges(Input.code()),
Optional(TypeLocRanges(
@@ -266,10 +266,10 @@
}
void target(
- $one_o[[Nonnull<$one_i[[int *]]>*]] p,
- $two_o[[std::unique_ptr<Nonnull<$two_i[[int*]]>>]] q,
- $three_o[[Nonnull<$three_i[[std::unique_ptr<int>]]>*]] r,
- $four_o[[std::unique_ptr<Nonnull<$four_i[[std::unique_ptr<int>]]>>]] s);
+ $one_o[[Nonnull<$one_i[[int *]]>*]] P,
+ $two_o[[std::unique_ptr<Nonnull<$two_i[[int*]]>>]] Q,
+ $three_o[[Nonnull<$three_i[[std::unique_ptr<int>]]>*]] R,
+ $four_o[[std::unique_ptr<Nonnull<$four_i[[std::unique_ptr<int>]]>>]] S);
)");
EXPECT_THAT(getFunctionRanges(Input.code()),
Optional(TypeLocRanges(
@@ -285,7 +285,7 @@
}
TEST(EligibleRangesTest, RefToPointer) {
- auto Input = Annotations("void target([[int *]]&p);");
+ auto Input = Annotations("void target([[int *]]&P);");
EXPECT_THAT(
getFunctionRanges(Input.code()),
Optional(TypeLocRanges(
@@ -297,7 +297,7 @@
template <typename One, typename Two>
struct S {};
- void target(S<$one[[int *]], $two[[$two_inner[[bool *]]*]]> p);
+ void target(S<$one[[int *]], $two[[$two_inner[[bool *]]*]]> P);
)");
EXPECT_THAT(getFunctionRanges(Input.code()),
Optional(TypeLocRanges(
@@ -313,8 +313,8 @@
struct S {};
void target(
- S<$one[[const int *]], $two_o[[$two_i[[const int *]] const *]]> p,
- S<$three[[int *]] const, $four_o[[$four_i[[int *]] const *]] const> q);
+ S<$one[[const int *]], $two_o[[$two_i[[const int *]] const *]]> P,
+ S<$three[[int *]] const, $four_o[[$four_i[[int *]] const *]] const> Q);
)");
EXPECT_THAT(getFunctionRanges(Input.code()),
Optional(TypeLocRanges(
@@ -334,8 +334,8 @@
class unique_ptr;
}
- void target($one[[std::unique_ptr<int>]] std_smart,
- Nonnull<$two[[std::unique_ptr<int>]]> nonnull_std_smart);
+ void target($one[[std::unique_ptr<int>]] StdSmart,
+ Nonnull<$two[[std::unique_ptr<int>]]> NonnullStdSmart);
)");
EXPECT_THAT(getFunctionRanges(Input.code()),
Optional(TypeLocRanges(
@@ -351,8 +351,8 @@
using pointer = int *;
};
- void target($one[[MySmartIntPtr]] user_defined_smart,
- Nonnull<$two[[MySmartIntPtr]]> nonnull_user_defined_smart);
+ void target($one[[MySmartIntPtr]] UserDefinedSmart,
+ Nonnull<$two[[MySmartIntPtr]]> NonnullUserDefinedSmart);
)");
EXPECT_THAT(getFunctionRanges(Input.code()),
Optional(TypeLocRanges(
@@ -368,8 +368,8 @@
using absl_nullability_compatible = void;
};
- void target($one[[MySmartPtr<int>]] user_defined_smart,
- Nonnull<$two[[MySmartPtr<int>]]> nonnull_user_defined_smart);
+ void target($one[[MySmartPtr<int>]] UserDefinedSmart,
+ Nonnull<$two[[MySmartPtr<int>]]> NonnullUserDefinedSmart);
)");
EXPECT_THAT(getFunctionRanges(Input.code()),
Optional(TypeLocRanges(
@@ -382,7 +382,7 @@
auto Input = Annotations(R"(
using IntPtr = int *;
- void target([[IntPtr]] a);
+ void target([[IntPtr]] P);
)");
EXPECT_THAT(
getFunctionRanges(Input.code()),
@@ -396,7 +396,7 @@
class TemplateClass {};
using Inaccessible = TemplateClass<int *>;
- void target(Inaccessible a);
+ void target(Inaccessible P);
)");
EXPECT_EQ(getFunctionRanges(Input.code()), std::nullopt);
}
@@ -405,7 +405,7 @@
auto Input = Annotations(R"(
using Nested = int **;
- void target($[[Nested]] a);
+ void target($[[Nested]] P);
)");
EXPECT_THAT(
getFunctionRanges(Input.code()),
@@ -418,7 +418,7 @@
template <typename T>
using AliasTemplate = T;
- void target(AliasTemplate<[[int*]]> a, AliasTemplate<int> b);
+ void target(AliasTemplate<[[int*]]> P, AliasTemplate<int> Q);
)");
EXPECT_THAT(
getFunctionRanges(Input.code()),
@@ -430,10 +430,10 @@
auto Input = Annotations(R"(
template <typename T>
struct S {
- using type = T;
+ using Type = T;
};
- void target(S<[[int *]]>::type a, S<int>::type b);
+ void target(S<[[int *]]>::Type P, S<int>::Type Q);
)");
EXPECT_THAT(
getFunctionRanges(Input.code()),
@@ -448,7 +448,7 @@
using type = T;
};
- void target(S<Nullable<[[int *]]>>::type a);
+ void target(S<Nullable<[[int *]]>>::type P);
)");
EXPECT_THAT(
getFunctionRanges(Input.code()),
@@ -467,7 +467,7 @@
using type = vector<T>::value_type;
};
- void target(S<[[int *]]>::type a);
+ void target(S<[[int *]]>::type P);
)");
EXPECT_THAT(
getFunctionRanges(Input.code()),
@@ -485,7 +485,7 @@
using type = U<T>;
};
- void target(S<[[int*]]>::type<vector> a);
+ void target(S<[[int*]]>::type<vector> P);
)");
EXPECT_THAT(
getFunctionRanges(Input.code()),
@@ -500,7 +500,7 @@
using value_type = V;
};
- void target(vector<$one[[$two[[$three[[int*]]*]]*]]>::value_type a);
+ void target(vector<$one[[$two[[$three[[int*]]*]]*]]>::value_type P);
)");
EXPECT_THAT(getFunctionRanges(Input.code()),
Optional(TypeLocRanges(
@@ -517,7 +517,7 @@
auto Input = Annotations(R"(
typedef void (*Alias)(const char *, ...);
- __attribute__((__noreturn__)) [[Alias]] target;
+ __attribute__((__noreturn__)) [[Alias]] Target;
)");
EXPECT_THAT(
getVarRanges(Input.code()),
@@ -532,7 +532,7 @@
struct Inner {};
};
- void target(Outer<[[int *]]>::Inner a);
+ void target(Outer<[[int *]]>::Inner P);
)");
EXPECT_THAT(
getFunctionRanges(Input.code()),
@@ -553,7 +553,7 @@
void target(
Outermost<$three[[char *]]>::Outer<$two[[int *]]>::Inner<$one[[bool *]]>
- a);
+ P);
)");
EXPECT_THAT(getFunctionRanges(Input.code()),
Optional(TypeLocRanges(
@@ -574,7 +574,7 @@
};
};
- void target(Outermost<[[int*]]>::Outer<bool>::Inner<char*> a);
+ void target(Outermost<[[int*]]>::Outer<bool>::Inner<char*> P);
)");
EXPECT_THAT(
getFunctionRanges(Input.code()),
@@ -591,7 +591,7 @@
using type = Pair<T , U>;
};
- void target(PairWrapper<$one[[int *]], $two[[bool *]]>::type a);
+ void target(PairWrapper<$one[[int *]], $two[[bool *]]>::type P);
)");
EXPECT_THAT(getFunctionRanges(Input.code()),
Optional(TypeLocRanges(
@@ -613,7 +613,7 @@
};
};
- void target(Outer<$one[[int *]]>::Inner<$two[[bool *]]>::type a);
+ void target(Outer<$one[[int *]]>::Inner<$two[[bool *]]>::type P);
)");
EXPECT_THAT(getFunctionRanges(Input.code()),
Optional(TypeLocRanges(
@@ -633,7 +633,7 @@
using Inner = Pair<T, U>;
};
- void target(Outer<$one[[int *]]>::Inner<$two[[bool *]]> a);
+ void target(Outer<$one[[int *]]>::Inner<$two[[bool *]]> P);
)");
EXPECT_THAT(getFunctionRanges(Input.code()),
@@ -655,7 +655,7 @@
using type = std::unique_ptr<T>;
};
- void target($unique_ptr[[S<$inner[[int*]]>::type]] a);
+ void target($unique_ptr[[S<$inner[[int*]]>::type]] P);
)");
EXPECT_THAT(getFunctionRanges(Input.code()),
Optional(TypeLocRanges(
@@ -676,9 +676,9 @@
using type = typename WrapT::template Alias<U> *;
};
- // a's canonical type is int**. The outer pointer's range is the whole type,
+ // P's canonical type is int**. The outer pointer's range is the whole type,
// and the inner pointer's range is the first template argument to S.
- void target($outer[[S<$inner[[int *]], Wrapper>::type]] a);
+ void target($outer[[S<$inner[[int *]], Wrapper>::type]] P);
)");
EXPECT_THAT(getFunctionRanges(Input.code()),
Optional(TypeLocRanges(
@@ -697,11 +697,11 @@
using Alias = P;
};
- // a's canonical type is int * and derives its nullability from the template
+ // P's canonical type is int * and derives its nullability from the template
// argument minus a layer of pointer indirection. But NullabilityWalker
// doesn't support resugaring template arguments in partial specializations,
// so we only see the pointer type at the alias' Loc.
- void target([[S<int **>::Alias]] a);
+ void target([[S<int **>::Alias]] P);
)");
EXPECT_THAT(
getFunctionRanges(Input.code()),
@@ -716,8 +716,8 @@
using type = int;
};
- void target(Tuple<$one[[int *]], $two[[$three[[int *]]*]]> a,
- Tuple<int *, int **>::type b);
+ void target(Tuple<$one[[int *]], $two[[$three[[int *]]*]]> P,
+ Tuple<int *, int **>::type Q);
)");
EXPECT_THAT(getFunctionRanges(Input.code()),
Optional(TypeLocRanges(
@@ -734,7 +734,7 @@
template <typename T1, typename T2 = T1>
using Alias = T2;
- void target(S<$one[[int *]]> a, $two[[Alias<int *>]] b);
+ void target(S<$one[[int *]]> P, $two[[Alias<int *>]] Q);
)");
EXPECT_THAT(getFunctionRanges(Input.code()),
Optional(TypeLocRanges(
@@ -757,7 +757,7 @@
template <typename T>
using Couple = Pair<T, T>;
- void target(Couple<[[int *]]> c);
+ void target(Couple<[[int *]]> P);
)");
EXPECT_THAT(
getFunctionRanges(Input.code()),
@@ -772,7 +772,7 @@
TEST(EligibleRangesTest, Field) {
auto Input = Annotations(R"(
struct S {
- $zero[[$one[[int *]]*]] target;
+ $zero[[$one[[int *]]*]] Target;
};
)");
EXPECT_THAT(getFieldRanges(Input.code()),
@@ -785,7 +785,7 @@
TEST(EligibleRangesTest, StaticFieldAkaGlobal) {
auto Input = Annotations(R"(
struct S {
- static $zero[[$one[[int *]]*]] target;
+ static $zero[[$one[[int *]]*]] Target;
};
)");
EXPECT_THAT(getVarRanges(Input.code()),
@@ -797,7 +797,7 @@
TEST(EligibleRangesTest, GlobalVariable) {
auto Input = Annotations(R"(
- $zero[[$one[[int *]]*]] target;
+ $zero[[$one[[int *]]*]] Target;
)");
EXPECT_THAT(getVarRanges(Input.code()),
Optional(TypeLocRanges(
@@ -808,7 +808,7 @@
TEST(EligibleRangesTest, Lambda) {
auto Input = Annotations(R"(
- auto lambda = []($one[[int *]]) -> $zero[[int *]] {};
+ auto Lambda = []($one[[int *]]) -> $zero[[int *]] {};
)");
EXPECT_THAT(getFunctionRanges(Input.code(), "operator()"),
Optional(TypeLocRanges(
@@ -823,8 +823,8 @@
template <typename T>
using ATemplate = T;
- void WithPartsOfWindowedValue(ATemplate<void(const int)> *f) {
- [&f]() { f(0); }();
+ void func(ATemplate<void(const int)> *P) {
+ [&P]() { P(0); }();
}
)cc";
// We expect no ranges for the lambda's implicit FieldDecl, which for some
@@ -852,7 +852,7 @@
Input = Annotations(R"(
#pragma nullability file_default nullable
- [[int*]] target;
+ [[int*]] Target;
)");
EXPECT_THAT(
getVarRanges(Input.code()),
@@ -862,7 +862,7 @@
Nullability::NULLABLE)));
Input = Annotations(R"(
- [[int*]] target;
+ [[int*]] Target;
)");
EXPECT_THAT(
getVarRanges(Input.code()),
@@ -873,21 +873,21 @@
TEST(EligibleRangesTest, RangesWithBareAutoTypeNotReturned) {
auto Input = Annotations(R"cc(
- $func_auto[[auto]] no_star(int* a) {
- a = nullptr;
- return a;
+ $func_auto[[auto]] noStar(int* P) {
+ P = nullptr;
+ return P;
}
int* getPtr();
- auto g_no_star = getPtr();
- auto _Nullable g_no_star_nullable = getPtr();
+ auto GNoStar = getPtr();
+ auto _Nullable GNoStarNullable = getPtr();
)cc");
- EXPECT_THAT(getFunctionRanges(Input.code(), "no_star"),
+ EXPECT_THAT(getFunctionRanges(Input.code(), "noStar"),
Optional(TypeLocRangesWithNoPragmaNullability(
MainFileName, Not(Contains(SlotRangeWithNoExistingAnnotation(
0, Input.range("func_auto")))))));
- EXPECT_EQ(getVarRanges(Input.code(), "g_no_star"), std::nullopt);
- EXPECT_EQ(getVarRanges(Input.code(), "g_no_star_nullable"), std::nullopt);
+ EXPECT_EQ(getVarRanges(Input.code(), "GNoStar"), std::nullopt);
+ EXPECT_EQ(getVarRanges(Input.code(), "GNoStarNullable"), std::nullopt);
}
MATCHER_P2(AutoSlotRangeWithNoExistingAnnotation, SlotID, Range, "") {
@@ -907,15 +907,15 @@
TEST(EligibleRangesTest, RangesWithAutoStarTypeReturnedWithMarker) {
auto Input = Annotations(R"(
- $func_auto[[auto*]] star($func_not_auto[[int*]] a) {
- a = nullptr;
- return a;
+ $func_auto[[auto*]] star($func_not_auto[[int*]] P) {
+ P = nullptr;
+ return P;
}
int* getPtr();
- $var_auto[[auto*]] g_star = getPtr();
- $var_auto_attributed[[auto*]] _Nullable g_star_nullable = getPtr();
- $var_auto_star_star[[$var_auto_star_inner[[auto*]]*]] g_star_star = &g_star;
+ $var_auto[[auto*]] GStar = getPtr();
+ $var_auto_attributed[[auto*]] _Nullable GStarNullable = getPtr();
+ $var_auto_star_star[[$var_auto_star_inner[[auto*]]*]] GStarStar = &GStar;
)");
EXPECT_THAT(getFunctionRanges(Input.code(), "star"),
Optional(TypeLocRangesWithNoPragmaNullability(
@@ -929,18 +929,18 @@
return SR.contains_auto_star();
},
testing::IsFalse()))))));
- EXPECT_THAT(getVarRanges(Input.code(), "g_star"),
+ EXPECT_THAT(getVarRanges(Input.code(), "GStar"),
Optional(TypeLocRangesWithNoPragmaNullability(
MainFileName,
UnorderedElementsAre(AutoSlotRangeWithNoExistingAnnotation(
0, Input.range("var_auto"))))));
- EXPECT_THAT(getVarRanges(Input.code(), "g_star_nullable"),
+ EXPECT_THAT(getVarRanges(Input.code(), "GStarNullable"),
Optional(TypeLocRangesWithNoPragmaNullability(
MainFileName, UnorderedElementsAre(AutoSlotRange(
0, Input.range("var_auto_attributed"),
Nullability::NULLABLE)))));
EXPECT_THAT(
- getVarRanges(Input.code(), "g_star_star"),
+ getVarRanges(Input.code(), "GStarStar"),
Optional(TypeLocRangesWithNoPragmaNullability(
MainFileName,
UnorderedElementsAre(AutoSlotRangeWithNoExistingAnnotation(
@@ -977,11 +977,11 @@
template <typename T>
using Nonnull = ::Nonnull<T>;
}
- void target($no[[int*]] p, absl::NullabilityUnknown<$yes[[int*]]> q,
+ void target($no[[int*]] P, absl::NullabilityUnknown<$yes[[int*]]> Q,
absl::/* a comment*/NullabilityUnknown< /* a comment */
- $with_comments[[int*]] /* a comment */ > r,
- absl::Nullable<$nullable[[int*]]> s,
- absl::Nonnull<$nonnull[[int*]]> t);
+ $with_comments[[int*]] /* a comment */ > R,
+ absl::Nullable<$nullable[[int*]]> S,
+ absl::Nonnull<$nonnull[[int*]]> T);
)");
EXPECT_THAT(
getFunctionRanges(Input.code()),
@@ -1008,7 +1008,7 @@
#define UNKNOWN(T) absl::NullabilityUnknown<T>
- void target(UNKNOWN([[int *]]) x);
+ void target(UNKNOWN([[int *]]) P);
)");
EXPECT_THAT(
getFunctionRanges(Input.code()),
@@ -1033,7 +1033,7 @@
using NullabilityUnknown = ::NullabilityUnknown<T>;
}
- void target(absl::NullabilityUnknown<[[std::unique_ptr<int>]]> x);
+ void target(absl::NullabilityUnknown<[[std::unique_ptr<int>]]> P);
)");
EXPECT_THAT(getFunctionRanges(Input.code()),
Optional(TypeLocRanges(
@@ -1052,10 +1052,10 @@
template <typename T>
using MyTemplateAlias = T;
- void target(MyTemplateAlias<absl::NullabilityUnknown<$nothing[[int *]]>> x,
- MyTemplateAlias<absl::NullabilityUnknown<$comment[[int *]]>/* a comment */> y,
+ void target(MyTemplateAlias<absl::NullabilityUnknown<$nothing[[int *]]>> P,
+ MyTemplateAlias<absl::NullabilityUnknown<$comment[[int *]]>/* a comment */> Q,
MyTemplateAlias<absl::NullabilityUnknown<$whitespace[[int *]]>
- > z);
+ > R);
)");
EXPECT_THAT(
getFunctionRanges(Input.code()),
@@ -1071,9 +1071,9 @@
TEST(ExistingAnnotationLengthTest, ClangAttribute) {
auto Input = Annotations(R"(
- void target($no[[int*]] p, $yes[[int*]] _Null_unspecified q,
- $with_comment[[int*]]/* a comment */_Null_unspecified r,
- $nullable[[int*]] _Nullable s, $nonnull[[int*]] _Nonnull t);
+ void target($no[[int*]] P, $yes[[int*]] _Null_unspecified Q,
+ $with_comment[[int*]]/* a comment */_Null_unspecified R,
+ $nullable[[int*]] _Nullable S, $nonnull[[int*]] _Nonnull T);
)");
EXPECT_THAT(
getFunctionRanges(Input.code()),
@@ -1120,7 +1120,7 @@
TEST(ComplexDeclaratorTest, FunctionPointer) {
auto Input = Annotations(R"(
- void target($func_pointer[[int (*$remove_from_type[[p]])(int, $pointer_param[[int*]])]]);
+ void target($func_pointer[[int (*$remove_from_type[[P]])(int, $pointer_param[[int*]])]]);
)");
EXPECT_THAT(
getFunctionRanges(Input.code()),
@@ -1128,7 +1128,7 @@
MainFileName,
UnorderedElementsAre(
AllOf(SlotRange(1, Input.range("func_pointer")),
- ComplexDeclarator("p", {Input.range("remove_from_type")})),
+ ComplexDeclarator("P", {Input.range("remove_from_type")})),
AllOf(SlotRange(-1, Input.range("pointer_param")),
NoComplexDeclarator())))));
@@ -1141,12 +1141,12 @@
}
TEST(ComplexDeclaratorTest, ArrayOfNonPointersHasNoRanges) {
- std::string Input = "void target(int p[]);";
+ std::string Input = "void target(int P[]);";
EXPECT_EQ(getFunctionRanges(Input), std::nullopt);
}
TEST(ComplexDeclaratorTest, ArrayOfSimplePointers) {
- auto Input = Annotations("void target([[int*]] p[]);");
+ auto Input = Annotations("void target([[int*]] P[]);");
EXPECT_THAT(
getFunctionRanges(Input.code()),
Optional(TypeLocRanges(
@@ -1158,14 +1158,14 @@
// Can't use ranges marked by [[...]] around arrays because of the adjacent
// closing square bracket at the end of the array length and the unfortunate
// syntax of Annotations, so use individual points.
- auto Input = Annotations("void target([[int (*$1^p[3]$2^)(float)]]);");
+ auto Input = Annotations("void target([[int (*$1^P[3]$2^)(float)]]);");
EXPECT_THAT(getFunctionRanges(Input.code()),
Optional(TypeLocRanges(
MainFileName,
UnorderedElementsAre(AllOf(
SlotRange(-1, Input.range()),
ComplexDeclarator(
- "p[3]", {Annotations::Range(Input.point("1"),
+ "P[3]", {Annotations::Range(Input.point("1"),
Input.point("2"))}))))));
// An unnamed array of function pointers. The array brackets are still moved.
@@ -1185,7 +1185,7 @@
// closing square bracket at the end of the array length and the unfortunate
// syntax of Annotations, so use individual points.
auto Input = Annotations(R"(
- void target($1^$range[[int*]] (*$3^p[3][2]$4^)[1]$2^);)");
+ void target($1^$range[[int*]] (*$3^P[3][2]$4^)[1]$2^);)");
EXPECT_THAT(
getFunctionRanges(Input.code()),
Optional(TypeLocRanges(
@@ -1195,7 +1195,7 @@
AllOf(SlotRange(-1, Annotations::Range(Input.point("1"),
Input.point("2"))),
ComplexDeclarator(
- "p[3][2]", {Annotations::Range(Input.point("3"),
+ "P[3][2]", {Annotations::Range(Input.point("3"),
Input.point("4"))}))))));
}
@@ -1204,7 +1204,7 @@
// closing square bracket at the end of the array length and the unfortunate
// syntax of Annotations, so use individual points.
auto Input =
- Annotations(R"(void target($1^int (*$remove_from_type[[p]])[]$2^);)");
+ Annotations(R"(void target($1^int (*$remove_from_type[[P]])[]$2^);)");
EXPECT_THAT(
getFunctionRanges(Input.code()),
Optional(TypeLocRanges(
@@ -1212,7 +1212,7 @@
UnorderedElementsAre(AllOf(
SlotRange(1,
Annotations::Range(Input.point("1"), Input.point("2"))),
- ComplexDeclarator("p", {Input.range("remove_from_type")}))))));
+ ComplexDeclarator("P", {Input.range("remove_from_type")}))))));
// An unnamed pointer to an array. There's nothing to move.
Input = Annotations(R"(void target($1^int (*)[]$2^);)");
@@ -1230,14 +1230,14 @@
// Can't use ranges marked by [[...]] around arrays because of the adjacent
// closing square bracket at the end of the array length and the unfortunate
// syntax of Annotations, so use individual points.
- auto Input = Annotations(R"(void target([[int (*$3^((p))[(1 + 2)]$4^)]]);)");
+ auto Input = Annotations(R"(void target([[int (*$3^((P))[(1 + 2)]$4^)]]);)");
EXPECT_THAT(
getFunctionRanges(Input.code()),
Optional(TypeLocRanges(
MainFileName,
UnorderedElementsAre(AllOf(
SlotRange(-1, Input.range()),
- ComplexDeclarator("((p))[(1 + 2)]",
+ ComplexDeclarator("((P))[(1 + 2)]",
{Annotations::Range(Input.point("3"),
Input.point("4"))}))))));
}
@@ -1247,14 +1247,14 @@
// closing square bracket at the end of the array length and the unfortunate
// syntax of Annotations, so use individual points.
auto Input =
- Annotations(R"(void target($1^int (*$star[[*]]$q[[q]])[1]$2^);)");
+ Annotations(R"(void target($1^int (*$star[[*]]$q[[Q]])[1]$2^);)");
EXPECT_THAT(getFunctionRanges(Input.code()),
Optional(TypeLocRanges(
MainFileName,
UnorderedElementsAre(
AllOf(SlotRange(1, Annotations::Range(Input.point("1"),
Input.point("2"))),
- ComplexDeclarator("q", {Input.range("q")})),
+ ComplexDeclarator("Q", {Input.range("q")})),
AllOf(SlotRange(-1, Annotations::Range(Input.point("1"),
Input.point("2"))),
ComplexDeclarator("*", {Input.range("star")}))))));
@@ -1265,19 +1265,19 @@
// closing square bracket at the end of the array length and the unfortunate
// syntax of Annotations, so use individual points.
auto Input = Annotations(
- R"(void target($whole[[void (*$1^(*$f[[(f)]])[]$2^)(int)]]);)");
+ R"(void target($whole[[void (*$1^(*$p[[(P)]])[]$2^)(int)]]);)");
EXPECT_THAT(
getFunctionRanges(Input.code()),
Optional(TypeLocRanges(
MainFileName,
UnorderedElementsAre(
AllOf(SlotRange(1, Input.range("whole")),
- ComplexDeclarator("(f)", {Input.range("f")})),
+ ComplexDeclarator("(P)", {Input.range("p")})),
AllOf(SlotRange(-1, Input.range("whole")),
ComplexDeclarator(
"(*)[]", {Annotations::Range(Input.point("1"),
- Input.range("f").Begin),
- Annotations::Range(Input.range("f").End,
+ Input.range("p").Begin),
+ Annotations::Range(Input.range("p").End,
Input.point("2"))}))))));
}
diff --git a/nullability/inference/infer_tu_test.cc b/nullability/inference/infer_tu_test.cc
index 0766c7a..c66ad1f 100644
--- a/nullability/inference/infer_tu_test.cc
+++ b/nullability/inference/infer_tu_test.cc
@@ -81,12 +81,12 @@
TEST_F(InferTUTest, UncheckedDeref) {
build(R"cc(
- void target(int *p, bool cond) {
- if (cond) *p;
+ void target(int *P, bool Cond) {
+ if (Cond) *P;
}
- void guarded(int *p) {
- if (p) *p;
+ void guarded(int *P) {
+ if (P) *P;
}
)cc");
@@ -97,8 +97,8 @@
TEST_F(InferTUTest, Samples) {
llvm::StringRef Code =
- "void target(int * p) { *p + *p; }\n"
- "void another(int x) { target(&x); }";
+ "void target(int * P) { *P + *P; }\n"
+ "void another(int X) { target(&X); }";
// 123456789012345678901234567890123456789
// 0 1 2 3
@@ -119,8 +119,8 @@
TEST_F(InferTUTest, Annotations) {
build(R"cc(
- Nonnull<int *> target(int *a, int *b);
- Nonnull<int *> target(int *a, Nullable<int *> p) { *p; }
+ Nonnull<int *> target(int *A, int *B);
+ Nonnull<int *> target(int *A, Nullable<int *> P) { *P; }
)cc");
EXPECT_THAT(infer(),
@@ -144,8 +144,8 @@
TEST_F(InferTUTest, ParamsFromCallSite) {
build(R"cc(
- void callee(int* p, int* q, int* r);
- void target(int* a, Nonnull<int*> b, Nullable<int*> c) { callee(a, b, c); }
+ void callee(int* P, int* Q, int* R);
+ void target(int* A, Nonnull<int*> B, Nullable<int*> C) { callee(A, B, C); }
)cc");
ASSERT_THAT(infer(),
@@ -179,8 +179,8 @@
TEST_F(InferTUTest, ReturnTypeNonnullAndUnknown) {
build(R"cc(
Nonnull<int*> providesNonnull();
- int* target(bool b, int* q) {
- if (b) return q;
+ int* target(bool B, int* Q) {
+ if (B) return Q;
return providesNonnull();
}
)cc");
@@ -192,8 +192,8 @@
TEST_F(InferTUTest, ReturnTypeNonnullAndNullable) {
build(R"cc(
Nonnull<int*> providesNonnull();
- int* target(bool b) {
- if (b) return nullptr;
+ int* target(bool B) {
+ if (B) return nullptr;
return providesNonnull();
}
)cc");
@@ -219,7 +219,7 @@
TEST_F(InferTUTest, PassedToNonnull) {
build(R"cc(
void takesNonnull(Nonnull<int*>);
- void target(int* p) { takesNonnull(p); }
+ void target(int* P) { takesNonnull(P); }
)cc");
EXPECT_THAT(infer(),
Contains(inference(hasName("target"),
@@ -229,7 +229,7 @@
TEST_F(InferTUTest, PassedToMutableNullableRef) {
build(R"cc(
void takesMutableNullableRef(Nullable<int*>&);
- void target(int* p) { takesMutableNullableRef(p); }
+ void target(int* P) { takesMutableNullableRef(P); }
)cc");
EXPECT_THAT(infer(),
Contains(inference(hasName("target"),
@@ -238,7 +238,7 @@
TEST_F(InferTUTest, AssignedFromNullable) {
build(R"cc(
- void target(int* p) { p = nullptr; }
+ void target(int* P) { P = nullptr; }
)cc");
EXPECT_THAT(infer(),
Contains(inference(hasName("target"),
@@ -248,8 +248,8 @@
TEST_F(InferTUTest, CHECKMacro) {
build(R"cc(
// macro must use the parameter, but otherwise body doesn't matter
-#define CHECK(x) x
- void target(int* p) { CHECK(p); }
+#define CHECK(X) X
+ void target(int* P) { CHECK(P); }
)cc");
EXPECT_THAT(infer(),
Contains(inference(hasName("target"),
@@ -259,13 +259,13 @@
TEST_F(InferTUTest, CHECKNEMacro) {
build(R"cc(
// macro must use the first parameter, but otherwise body doesn't matter
-#define CHECK_NE(x, y) x
- void target(int* p, int* q, int* r, int* s) {
- CHECK_NE(p, nullptr);
- CHECK_NE(nullptr, q);
- int* a = nullptr;
- CHECK_NE(a, r);
- CHECK_NE(s, a);
+#define CHECK_NE(X, Y) X
+ void target(int* P, int* Q, int* R, int* S) {
+ CHECK_NE(P, nullptr);
+ CHECK_NE(nullptr, Q);
+ int* A = nullptr;
+ CHECK_NE(A, R);
+ CHECK_NE(S, A);
}
)cc");
EXPECT_THAT(
@@ -275,64 +275,64 @@
inferredSlot(2, Nullability::NONNULL),
inferredSlot(3, Nullability::NONNULL),
inferredSlot(4, Nullability::NONNULL)}),
- inference(hasName("a"), {inferredSlot(0, Nullability::NULLABLE)})));
+ inference(hasName("A"), {inferredSlot(0, Nullability::NULLABLE)})));
}
TEST_F(InferTUTest, Fields) {
build(R"cc(
int* getIntPtr();
struct S {
- int* unchecked_deref;
- int* default_null_and_unchecked_deref = nullptr;
- int* uninitialized;
+ int* UncheckedDeref;
+ int* DefaultNullAndUncheckedDeref = nullptr;
+ int* Uninitialized;
int NotATarget = *getIntPtr();
void method() {
- *unchecked_deref;
- *default_null_and_unchecked_deref;
+ *UncheckedDeref;
+ *DefaultNullAndUncheckedDeref;
}
};
void foo() {
// Use the implicitly-declared default constructor so that it will be
// generated.
- S s;
+ S AnS;
}
class C {
public:
- C() : null_constructor_init(nullptr) {
- null_in_constructor_and_unchecked_deref = nullptr;
- null_in_constructor = nullptr;
+ C() : NullConstructorInit(nullptr) {
+ NullInConstructorAndUncheckedDeref = nullptr;
+ NullInConstructor = nullptr;
}
- void method() { *null_in_constructor_and_unchecked_deref; }
+ void method() { *NullInConstructorAndUncheckedDeref; }
private:
- int* null_in_constructor_and_unchecked_deref;
- int* null_constructor_init;
- int* null_in_constructor;
+ int* NullInConstructorAndUncheckedDeref;
+ int* NullConstructorInit;
+ int* NullInConstructor;
};
)cc");
EXPECT_THAT(
infer(),
UnorderedElementsAre(
- inference(hasName("unchecked_deref"),
+ inference(hasName("UncheckedDeref"),
{inferredSlot(0, Nullability::NONNULL)}),
// Unchecked deref is strong evidence and a default null
// member initializer is weak.
- inference(hasName("default_null_and_unchecked_deref"),
+ inference(hasName("DefaultNullAndUncheckedDeref"),
{inferredSlot(0, Nullability::NONNULL)}),
// No inference for uninitialized.,
inference(hasName("getIntPtr"),
{inferredSlot(0, Nullability::NONNULL)}),
// Initialization to null in the constructor or another
// function body is strong, producing a conflict.
- inference(hasName("null_in_constructor_and_unchecked_deref"),
+ inference(hasName("NullInConstructorAndUncheckedDeref"),
{inferredSlot(0, Nullability::NONNULL, /*Conflict*/ true)}),
- inference(hasName("null_constructor_init"),
+ inference(hasName("NullConstructorInit"),
{inferredSlot(0, Nullability::NULLABLE)}),
- inference(hasName("null_in_constructor"),
+ inference(hasName("NullInConstructor"),
{inferredSlot(0, Nullability::NULLABLE)})));
}
@@ -345,7 +345,7 @@
char *C = static_cast<char *>(nullptr);
};
- void foo(S s);
+ void foo(S AnS);
)cc");
// Because the implicitly-declared default constructor is never used, it is
// not present in the AST and we never analyze it. So, we collect no evidence
@@ -367,7 +367,7 @@
// A use of the implicitly-declared default constructor, so it is generated
// and included in the AST for us to analyze, allowing us to infer from
// default member initializers.
- void foo() { S s; }
+ void foo() { S AnS; }
)cc");
EXPECT_THAT(
infer(),
@@ -451,20 +451,20 @@
void func() { auto AutoLocal = getNullable(); }
- int *autoParamAkaTemplate(auto p) {
+ int *autoParamAkaTemplate(auto P) {
auto AutoLocalInTemplate = getNullable();
- *p;
+ *P;
return getNullable();
}
- auto autoReturn(int *q) {
- *q;
+ auto autoReturn(int *Q) {
+ *Q;
auto AutoLocalInAutoReturn = getNullable();
return getNullable();
}
- auto autoReturnAndParam(auto r) {
- *r;
+ auto autoReturnAndParam(auto R) {
+ *R;
return getNullable();
}
)cc");
@@ -495,20 +495,20 @@
void func() { auto *AutoStarLocal = getNullable(); }
- int *autoStarParamAkaTemplate(auto *p) {
+ int *autoStarParamAkaTemplate(auto *P) {
auto *AutoStarLocalInTemplate = getNullable();
- *p;
+ *P;
return getNullable();
}
- auto *autoStarReturn(int *q) {
- *q;
+ auto *autoStarReturn(int *Q) {
+ *Q;
auto *AutoStarLocalInAutoStarReturn = getNullable();
return getNullable();
}
- auto *autoStarReturnAndParam(auto *r) {
- *r;
+ auto *autoStarReturnAndParam(auto *R) {
+ *R;
return getNullable();
}
)cc");
@@ -535,13 +535,13 @@
TEST_F(InferTUTest, IterationsPropagateInferences) {
build(R"cc(
- void takesToBeNonnull(int* x) { *x; }
- int* returnsToBeNonnull(int* a) { return a; }
- int* target(int* p, int* q, int* r) {
- *p;
- takesToBeNonnull(q);
- q = r;
- return returnsToBeNonnull(p);
+ void takesToBeNonnull(int* X) { *X; }
+ int* returnsToBeNonnull(int* A) { return A; }
+ int* target(int* P, int* Q, int* R) {
+ *P;
+ takesToBeNonnull(Q);
+ Q = R;
+ return returnsToBeNonnull(P);
}
)cc");
EXPECT_THAT(
@@ -595,13 +595,13 @@
TEST_F(InferTUTest, Pragma) {
build(R"cc(
#pragma nullability file_default nonnull
- void target(int* default_nonnull, NullabilityUnknown<int*> inferred_nonnull,
- Nullable<int*> nullable,
- NullabilityUnknown<int*> inferred_nullable,
- NullabilityUnknown<int*> unknown) {
- default_nonnull = inferred_nonnull;
- default_nonnull = nullptr;
- inferred_nullable = nullable;
+ void target(int* DefaultNonnull, NullabilityUnknown<int*> InferredNonnull,
+ Nullable<int*> Nullable,
+ NullabilityUnknown<int*> InferredNullable,
+ NullabilityUnknown<int*> Unknown) {
+ DefaultNonnull = InferredNonnull;
+ DefaultNonnull = nullptr;
+ InferredNullable = Nullable;
}
)cc");
EXPECT_THAT(infer(),
@@ -629,11 +629,11 @@
TEST_F(InferTUSmartPointerTest, Annotations) {
build(R"cc(
#include <memory>
- Nonnull<std::unique_ptr<int>> target(std::unique_ptr<int> a,
- std::unique_ptr<int> b);
- Nonnull<std::unique_ptr<int>> target(std::unique_ptr<int> a,
- Nullable<std::unique_ptr<int>> p) {
- *p;
+ Nonnull<std::unique_ptr<int>> target(std::unique_ptr<int> A,
+ std::unique_ptr<int> B);
+ Nonnull<std::unique_ptr<int>> target(std::unique_ptr<int> A,
+ Nullable<std::unique_ptr<int>> P) {
+ *P;
}
)cc");
@@ -649,11 +649,11 @@
build(R"cc(
#include <memory>
#include <utility>
- void callee(std::unique_ptr<int> p, std::unique_ptr<int> q,
- std::unique_ptr<int> r);
- void target(std::unique_ptr<int> a, Nonnull<std::unique_ptr<int>> b,
- Nullable<std::unique_ptr<int>> c) {
- callee(std::move(a), std::move(b), std::move(c));
+ void callee(std::unique_ptr<int> P, std::unique_ptr<int> Q,
+ std::unique_ptr<int> R);
+ void target(std::unique_ptr<int> A, Nonnull<std::unique_ptr<int>> B,
+ Nullable<std::unique_ptr<int>> C) {
+ callee(std::move(A), std::move(B), std::move(C));
}
)cc");
@@ -691,17 +691,17 @@
TEST_F(InferTUVirtualMethodsTest, SafeVarianceNoConflicts) {
build(R"cc(
struct Base {
- virtual int* foo(int* p) {
- *p;
+ virtual int* foo(int* P) {
+ *P;
return nullptr;
}
};
struct Derived : public Base {
- int* foo(int* p) override {
- static int i = 0;
- p = nullptr;
- return &i;
+ int* foo(int* P) override {
+ static int I = 0;
+ P = nullptr;
+ return &I;
}
};
)cc");
@@ -719,15 +719,15 @@
TEST_F(InferTUVirtualMethodsTest, BaseConstrainsDerived) {
build(R"cc(
struct Base {
- virtual Nonnull<int*> foo(int* p) {
- static int i = 0;
- p = nullptr;
- return &i;
+ virtual Nonnull<int*> foo(int* P) {
+ static int I = 0;
+ P = nullptr;
+ return &I;
}
};
struct Derived : public Base {
- int* foo(int* p) override;
+ int* foo(int* P) override;
};
)cc");
@@ -744,12 +744,12 @@
TEST_F(InferTUVirtualMethodsTest, DerivedConstrainsBase) {
build(R"cc(
struct Base {
- virtual int* foo(int* p);
+ virtual int* foo(int* P);
};
struct Derived : public Base {
- int* foo(int* p) override {
- *p;
+ int* foo(int* P) override {
+ *P;
return nullptr;
}
};
@@ -767,12 +767,12 @@
TEST_F(InferTUVirtualMethodsTest, Conflict) {
build(R"cc(
struct Base {
- virtual int* foo(int* p);
+ virtual int* foo(int* P);
};
struct Derived : public Base {
- int* foo(int* p) override {
- *p;
+ int* foo(int* P) override {
+ *P;
return nullptr;
}
};
@@ -801,15 +801,15 @@
TEST_F(InferTUVirtualMethodsTest, MultipleDerived) {
build(R"cc(
struct Base {
- virtual void foo(int* p) { p = nullptr; }
+ virtual void foo(int* P) { P = nullptr; }
};
struct DerivedA : public Base {
- void foo(int* p) override;
+ void foo(int* P) override;
};
struct DerivedB : public Base {
- void foo(int* p) override;
+ void foo(int* P) override;
};
)cc");
EXPECT_THAT(infer(),
@@ -825,15 +825,15 @@
TEST_F(InferTUVirtualMethodsTest, MultipleBase) {
build(R"cc(
struct BaseA {
- virtual void foo(int* p);
+ virtual void foo(int* P);
};
struct BaseB {
- virtual void foo(int* p);
+ virtual void foo(int* P);
};
struct Derived : public BaseA, public BaseB {
- void foo(int* p) override { *p; }
+ void foo(int* P) override { *P; }
};
)cc");