https://github.com/usx95 updated 
https://github.com/llvm/llvm-project/pull/174741

>From 218b3a5e3983d74f25fe5979860d8f6b76f1222c Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena <[email protected]>
Date: Tue, 16 Dec 2025 12:13:42 +0000
Subject: [PATCH] only-for-owners

---
 clang/lib/Analysis/LifetimeSafety/LifetimeAnnotations.cpp | 3 ++-
 clang/test/Sema/warn-lifetime-analysis-nocfg.cpp          | 4 +++-
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Analysis/LifetimeSafety/LifetimeAnnotations.cpp 
b/clang/lib/Analysis/LifetimeSafety/LifetimeAnnotations.cpp
index 2772fe20de19b..f6afc43843a82 100644
--- a/clang/lib/Analysis/LifetimeSafety/LifetimeAnnotations.cpp
+++ b/clang/lib/Analysis/LifetimeSafety/LifetimeAnnotations.cpp
@@ -99,7 +99,8 @@ bool shouldTrackImplicitObjectArg(const CXXMethodDecl 
*Callee) {
   if (!isGslPointerType(Callee->getFunctionObjectParameterType()) &&
       !isGslOwnerType(Callee->getFunctionObjectParameterType()))
     return false;
-  if (isPointerLikeType(Callee->getReturnType())) {
+  if (isPointerLikeType(Callee->getReturnType()) &&
+      isGslOwnerType(Callee->getFunctionObjectParameterType())) {
     if (!Callee->getIdentifier())
       return false;
     return llvm::StringSwitch<bool>(Callee->getName())
diff --git a/clang/test/Sema/warn-lifetime-analysis-nocfg.cpp 
b/clang/test/Sema/warn-lifetime-analysis-nocfg.cpp
index 7634dbf2f6733..b04ed86cd8abd 100644
--- a/clang/test/Sema/warn-lifetime-analysis-nocfg.cpp
+++ b/clang/test/Sema/warn-lifetime-analysis-nocfg.cpp
@@ -249,8 +249,10 @@ int &doNotFollowReferencesForLocalOwner() {
   return p; // ok
 }
 
+// It is not possible to annotate accessors of view types 
+// (like std::string_view::begin()) to catch bugs like the following:
 const char *trackThroughMultiplePointer() {
-  return std::basic_string_view<char>(std::basic_string<char>()).begin(); // 
expected-warning {{returning address of local temporary object}}
+  return std::basic_string_view<char>(std::basic_string<char>()).begin();
 }
 
 struct X {

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

Reply via email to