https://github.com/HerrCai0907 created 
https://github.com/llvm/llvm-project/pull/91160

None

>From 8ba443f10a0fa65c319e5149a289d65f89a94d26 Mon Sep 17 00:00:00 2001
From: Congcong Cai <congcongcai0...@163.com>
Date: Mon, 6 May 2024 10:58:23 +0800
Subject: [PATCH] [NFC][clang-tidy]increase stability for
 bugprone-return-const-ref-from-parameter

---
 .../bugprone/ReturnConstRefFromParameterCheck.cpp        | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git 
a/clang-tools-extra/clang-tidy/bugprone/ReturnConstRefFromParameterCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/ReturnConstRefFromParameterCheck.cpp
index b3f7dd6d1c86f8..cacba38b4a5aa8 100644
--- a/clang-tools-extra/clang-tidy/bugprone/ReturnConstRefFromParameterCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/ReturnConstRefFromParameterCheck.cpp
@@ -29,10 +29,13 @@ void 
ReturnConstRefFromParameterCheck::registerMatchers(MatchFinder *Finder) {
 void ReturnConstRefFromParameterCheck::check(
     const MatchFinder::MatchResult &Result) {
   const auto *R = Result.Nodes.getNodeAs<ReturnStmt>("ret");
-  diag(R->getRetValue()->getBeginLoc(),
-       "returning a constant reference parameter may cause a use-after-free "
+  const SourceRange Range = R->getRetValue()->getSourceRange();
+  if (Range.isInvalid())
+    return;
+  diag(Range.getBegin(),
+       "returning a constant reference parameter may cause use-after-free "
        "when the parameter is constructed from a temporary")
-      << R->getRetValue()->getSourceRange();
+      << Range;
 }
 
 } // namespace clang::tidy::bugprone

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to