The const-member modeling doesn't handle functions that return references.

Bail out instead of crashing.

PiperOrigin-RevId: 582645090
Change-Id: Ib74e04b87607029c8e48539706d542b28dec5d12
diff --git a/nullability/pointer_nullability_analysis.cc b/nullability/pointer_nullability_analysis.cc
index 3c67092..0afdf13 100644
--- a/nullability/pointer_nullability_analysis.cc
+++ b/nullability/pointer_nullability_analysis.cc
@@ -539,7 +539,7 @@
 void transferFlowSensitiveConstMemberCall(
     const CXXMemberCallExpr *MCE, const MatchFinder::MatchResult &Result,
     TransferState<PointerNullabilityLattice> &State) {
-  if (!isSupportedRawPointerType(MCE->getType())) {
+  if (!isSupportedRawPointerType(MCE->getType()) || !MCE->isPRValue()) {
     // We can't handle it as a special case, but still need to handle it.
     transferFlowSensitiveCallExpr(MCE, Result, State);
     return;
diff --git a/nullability/test/function_calls.cc b/nullability/test/function_calls.cc
index af020fd..924d9c4 100644
--- a/nullability/test/function_calls.cc
+++ b/nullability/test/function_calls.cc
@@ -695,6 +695,20 @@
   )cc"));
 }
 
+// Special modeling of accessors is not implemented for accessors references.
+TEST(PointerNullabilityTest, ConstMethodReturnsReference) {
+  EXPECT_TRUE(checkDiagnostics(R"cc(
+    struct C {
+      int *const _Nullable &property() const { return x; }
+      int *_Nullable x = nullptr;
+    };
+    void target() {
+      C obj;
+      if (obj.property() != nullptr) *obj.property();  // [[unsafe]]
+    }
+  )cc"));
+}
+
 TEST(PointerNullabilityTest, ConstMethodEarlyReturn) {
   EXPECT_TRUE(checkDiagnostics(R"cc(
     struct C {