aboutsummaryrefslogtreecommitdiff
path: root/clang/unittests/Analysis/FlowSensitive/UncheckedStatusOrAccessModelTestFixture.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'clang/unittests/Analysis/FlowSensitive/UncheckedStatusOrAccessModelTestFixture.cpp')
-rw-r--r--clang/unittests/Analysis/FlowSensitive/UncheckedStatusOrAccessModelTestFixture.cpp104
1 files changed, 104 insertions, 0 deletions
diff --git a/clang/unittests/Analysis/FlowSensitive/UncheckedStatusOrAccessModelTestFixture.cpp b/clang/unittests/Analysis/FlowSensitive/UncheckedStatusOrAccessModelTestFixture.cpp
index 4bb09d3..425beb9 100644
--- a/clang/unittests/Analysis/FlowSensitive/UncheckedStatusOrAccessModelTestFixture.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/UncheckedStatusOrAccessModelTestFixture.cpp
@@ -2871,6 +2871,110 @@ TEST_P(UncheckedStatusOrAccessModelTest, EqualityCheck) {
)cc");
}
+TEST_P(UncheckedStatusOrAccessModelTest, PointerEqualityCheck) {
+ ExpectDiagnosticsFor(
+ R"cc(
+#include "unchecked_statusor_access_test_defs.h"
+
+ void target(STATUSOR_INT* x, STATUSOR_INT* y) {
+ if (x->ok()) {
+ if (x == y)
+ y->value();
+ else
+ y->value(); // [[unsafe]]
+ }
+ }
+ )cc");
+ ExpectDiagnosticsFor(
+ R"cc(
+#include "unchecked_statusor_access_test_defs.h"
+
+ void target(STATUSOR_INT* x, STATUSOR_INT* y) {
+ if (x->ok()) {
+ if (x != y)
+ y->value(); // [[unsafe]]
+ else
+ y->value();
+ }
+ }
+ )cc");
+ ExpectDiagnosticsFor(
+ R"cc(
+#include "unchecked_statusor_access_test_defs.h"
+
+ void target(STATUS* x, STATUS* y) {
+ auto sor = Make<STATUSOR_INT>();
+ if (x->ok()) {
+ if (x == y && sor.status() == *y)
+ sor.value();
+ else
+ sor.value(); // [[unsafe]]
+ }
+ }
+ )cc");
+ ExpectDiagnosticsFor(
+ R"cc(
+#include "unchecked_statusor_access_test_defs.h"
+
+ void target(STATUS* x, STATUS* y) {
+ auto sor = Make<STATUSOR_INT>();
+ if (x->ok()) {
+ if (x != y)
+ sor.value(); // [[unsafe]]
+ else if (sor.status() == *y)
+ sor.value();
+ }
+ }
+ )cc");
+}
+
+TEST_P(UncheckedStatusOrAccessModelTest, Emplace) {
+ ExpectDiagnosticsFor(R"cc(
+#include "unchecked_statusor_access_test_defs.h"
+
+ struct Foo {
+ Foo(int);
+ };
+
+ void target(absl::StatusOr<Foo> sor, int value) {
+ sor.emplace(value);
+ sor.value();
+ }
+ )cc");
+ ExpectDiagnosticsFor(R"cc(
+#include "unchecked_statusor_access_test_defs.h"
+
+ struct Foo {
+ Foo(std::initializer_list<int>, int);
+ };
+
+ void target(absl::StatusOr<Foo> sor, int value) {
+ sor.emplace({1, 2, 3}, value);
+ sor.value();
+ }
+ )cc");
+ ExpectDiagnosticsFor(R"cc(
+#include "unchecked_statusor_access_test_defs.h"
+
+ void target() {
+ STATUSOR_INT sor;
+ bool sor_ok = sor.ok();
+ if (!sor_ok)
+ sor.emplace(42);
+ sor.value();
+ }
+ )cc");
+ ExpectDiagnosticsFor(R"cc(
+#include "unchecked_statusor_access_test_defs.h"
+
+ void target(bool b) {
+ STATUSOR_INT sor;
+ if (b) sor.emplace(42);
+ if (b) sor.value();
+ }
+ )cc");
+}
+
} // namespace
std::string