[clang] [clang] Fix false positive regression for lifetime analysis warning. (PR #127460)

Utkarsh Saxena via cfe-commits cfe-commits at lists.llvm.org
Mon Feb 17 04:12:16 PST 2025


================
@@ -1239,11 +1239,12 @@ static AnalysisResult analyzePathForGSLPointer(const IndirectLocalPath &Path,
     }
     // Check the return type, e.g.
     //   const GSLOwner& func(const Foo& foo [[clang::lifetimebound]])
+    //   GSLOwner* func(cosnt Foo& foo [[clang::lifetimebound]])
     //   GSLPointer func(const Foo& foo [[clang::lifetimebound]])
     if (FD &&
-        ((FD->getReturnType()->isReferenceType() &&
+        ((FD->getReturnType()->isPointerOrReferenceType() &&
           isRecordWithAttr<OwnerAttr>(FD->getReturnType()->getPointeeType())) ||
-         isPointerLikeType(FD->getReturnType())))
+          isGLSPointerType(FD->getReturnType())))
----------------
usx95 wrote:

Does it mean that only `gsl::Pointer` return types are supported ?

For example `std::unique_ptr` in `int* x = make_unique<int>(1).get();`
https://godbolt.org/z/73bTWd48b
I think this would stop working ?

https://github.com/llvm/llvm-project/pull/127460


More information about the cfe-commits mailing list