Author: Florian Mayer
Date: 2026-02-06T13:46:07-08:00
New Revision: b74f8ad0092ab74b2b93bf3ccd22e48181b4d2d2

URL: 
https://github.com/llvm/llvm-project/commit/b74f8ad0092ab74b2b93bf3ccd22e48181b4d2d2
DIFF: 
https://github.com/llvm/llvm-project/commit/b74f8ad0092ab74b2b93bf3ccd22e48181b4d2d2.diff

LOG: [NFC] [FlowSensitive] [StatusOr] Add tests for member accesses



Reviewers: jvoung

Reviewed By: jvoung

Pull Request: https://github.com/llvm/llvm-project/pull/180077

Added: 
    

Modified: 
    
clang/unittests/Analysis/FlowSensitive/UncheckedStatusOrAccessModelTestFixture.cpp

Removed: 
    


################################################################################
diff  --git 
a/clang/unittests/Analysis/FlowSensitive/UncheckedStatusOrAccessModelTestFixture.cpp
 
b/clang/unittests/Analysis/FlowSensitive/UncheckedStatusOrAccessModelTestFixture.cpp
index 45c9cb2725251..f842abe9e454a 100644
--- 
a/clang/unittests/Analysis/FlowSensitive/UncheckedStatusOrAccessModelTestFixture.cpp
+++ 
b/clang/unittests/Analysis/FlowSensitive/UncheckedStatusOrAccessModelTestFixture.cpp
@@ -1950,6 +1950,119 @@ TEST_P(UncheckedStatusOrAccessModelTest, QcheckNeMacro) 
{
   )cc");
 }
 
+TEST_P(UncheckedStatusOrAccessModelTest, Member) {
+  // The following examples are not sound as there could be member calls 
between
+  // the ok() and the value() calls that change the StatusOr value.
+  ExpectDiagnosticsFor(R"cc(
+#include "unchecked_statusor_access_test_defs.h"
+
+    struct Foo {
+      STATUSOR_INT bar;
+    };
+
+    void target() {
+      Foo foo;
+      if (foo.bar.ok()) foo.bar.value();
+    }
+  )cc");
+  ExpectDiagnosticsFor(R"cc(
+#include "unchecked_statusor_access_test_defs.h"
+
+    struct Foo {
+      STATUSOR_INT sor;
+    };
+
+    void target(Foo foo) {
+      foo.sor.value();  // [[unsafe]]
+    }
+  )cc");
+  ExpectDiagnosticsFor(R"cc(
+#include "unchecked_statusor_access_test_defs.h"
+
+    struct Foo {
+      STATUSOR_INT sor;
+    };
+
+    void target(Foo foo) {
+      if (foo.sor.ok())
+        foo.sor.value();
+      else
+        foo.sor.value();  // [[unsafe]]
+    }
+  )cc");
+  ExpectDiagnosticsFor(R"cc(
+#include "unchecked_statusor_access_test_defs.h"
+
+    struct Foo {
+      STATUSOR_INT sor;
+    };
+
+    void target(Foo foo) {
+      if (foo.sor.status().ok())
+        foo.sor.value();
+      else
+        foo.sor.value();  // [[unsafe]]
+    }
+  )cc");
+  ExpectDiagnosticsFor(R"cc(
+#include "unchecked_statusor_access_test_defs.h"
+
+    struct Foo {
+      STATUSOR_INT sor;
+
+      void target() {
+        if (sor.ok())
+          sor.value();
+        else
+          sor.value();  // [[unsafe]]
+      }
+    };
+  )cc");
+  ExpectDiagnosticsFor(R"cc(
+#include "unchecked_statusor_access_test_defs.h"
+
+    struct Foo {
+      STATUSOR_INT sor;
+
+      void target(bool b) {
+        if (b) {
+          if (!sor.ok()) return;
+        } else {
+          if (!sor.ok()) return;
+        }
+        sor.value();
+      }
+    };
+  )cc");
+  ExpectDiagnosticsFor(R"cc(
+#include "unchecked_statusor_access_test_defs.h"
+
+    struct Foo {
+      struct Bar {
+        STATUSOR_INT sor;
+
+        void target() {
+          if (sor.ok())
+            sor.value();
+          else
+            sor.value();  // [[unsafe]]
+        }
+      };
+    };
+  )cc");
+  ExpectDiagnosticsFor(R"cc(
+#include "unchecked_statusor_access_test_defs.h"
+
+    struct Foo {
+      STATUSOR_INT sor;
+    };
+
+    void target() {
+      Foo().sor.value();  // [[unsafe]]
+    }
+  )cc");
+}
+
 TEST_P(UncheckedStatusOrAccessModelTest, GlobalVars) {
   // The following examples are not sound as there could be opaque calls 
between
   // the ok() and the value() calls that change the StatusOr value.


        
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to