https://github.com/rohanjr created 
https://github.com/llvm/llvm-project/pull/184867

This prevents a crash if the range text is invalid.

>From 5d8c0407b3c7fee22cb5c9c66ff17b3d86841296 Mon Sep 17 00:00:00 2001
From: Rohan Jacob-Rao <[email protected]>
Date: Thu, 5 Mar 2026 19:51:15 +0000
Subject: [PATCH] [NFC][Clang][FixitUtil] Check optional value before
 dereference.

This prevents a crash if the range text is invalid.
---
 clang/lib/Analysis/FixitUtil.cpp | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Analysis/FixitUtil.cpp b/clang/lib/Analysis/FixitUtil.cpp
index 4ac3f3acd8c62..ec1924f9c3e10 100644
--- a/clang/lib/Analysis/FixitUtil.cpp
+++ b/clang/lib/Analysis/FixitUtil.cpp
@@ -89,8 +89,12 @@ clang::getPointeeTypeText(const DeclaratorDecl *VD, const 
SourceManager &SM,
     // `PteTy` via source ranges.
     *QualifiersToAppend = PteTy.getQualifiers();
   }
-  return getRangeText({PteTyLoc.getBeginLoc(), PteEndOfTokenLoc}, SM, LangOpts)
-      ->str();
+
+  std::optional<StringRef> RangeText =
+      getRangeText({PteTyLoc.getBeginLoc(), PteEndOfTokenLoc}, SM, LangOpts);
+  if (!RangeText)
+    return std::nullopt;
+  return RangeText->str();
 }
 
 // returns text of pointee to pointee (T*&)

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

Reply via email to