https://github.com/zeyi2 created 
https://github.com/llvm/llvm-project/pull/170004

This patch is currently work in progress.

Currently `ClangTidyDiagnosticConsumer` is not fixed.

Closes [#156151](https://github.com/llvm/llvm-project/issues/156151)

>From 026c03ac0ceb4a94c00f97535cc7f2f64d51ab84 Mon Sep 17 00:00:00 2001
From: mtx <[email protected]>
Date: Sat, 29 Nov 2025 22:53:37 +0800
Subject: [PATCH 01/13] [clang-tidy] Fix bugprone-unchecked-optional-access in
 ClangTidyProfiling

---
 .../clang-tidy/ClangTidyProfiling.cpp         | 22 +++++++++----------
 .../clang-tidy/ClangTidyProfiling.h           |  5 +++--
 2 files changed, 14 insertions(+), 13 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/ClangTidyProfiling.cpp 
b/clang-tools-extra/clang-tidy/ClangTidyProfiling.cpp
index 6fee154be448c..7f8b2e9b66209 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyProfiling.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidyProfiling.cpp
@@ -43,10 +43,11 @@ void 
ClangTidyProfiling::printUserFriendlyTable(llvm::raw_ostream &OS,
 }
 
 void ClangTidyProfiling::printAsJSON(llvm::raw_ostream &OS,
-                                     llvm::TimerGroup &TG) {
+                                     llvm::TimerGroup &TG,
+                                     const StorageParams &Storage) {
   OS << "{\n";
-  OS << R"("file": ")" << Storage->SourceFilename << "\",\n";
-  OS << R"("timestamp": ")" << Storage->Timestamp << "\",\n";
+  OS << R"("file": ")" << Storage.SourceFilename << "\",\n";
+  OS << R"("timestamp": ")" << Storage.Timestamp << "\",\n";
   OS << "\"profile\": {\n";
   TG.printJSONValues(OS, "");
   OS << "\n}\n";
@@ -54,10 +55,9 @@ void ClangTidyProfiling::printAsJSON(llvm::raw_ostream &OS,
   OS.flush();
 }
 
-void ClangTidyProfiling::storeProfileData(llvm::TimerGroup &TG) {
-  assert(Storage && "We should have a filename.");
-
-  llvm::SmallString<256> OutputDirectory(Storage->StoreFilename);
+void ClangTidyProfiling::storeProfileData(llvm::TimerGroup &TG,
+                                          const StorageParams &Storage) {
+  llvm::SmallString<256> OutputDirectory(Storage.StoreFilename);
   llvm::sys::path::remove_filename(OutputDirectory);
   if (const std::error_code EC =
           llvm::sys::fs::create_directories(OutputDirectory)) {
@@ -67,14 +67,14 @@ void ClangTidyProfiling::storeProfileData(llvm::TimerGroup 
&TG) {
   }
 
   std::error_code EC;
-  llvm::raw_fd_ostream OS(Storage->StoreFilename, EC, llvm::sys::fs::OF_None);
+  llvm::raw_fd_ostream OS(Storage.StoreFilename, EC, llvm::sys::fs::OF_None);
   if (EC) {
-    llvm::errs() << "Error opening output file '" << Storage->StoreFilename
+    llvm::errs() << "Error opening output file '" << Storage.StoreFilename
                  << "': " << EC.message() << "\n";
     return;
   }
 
-  printAsJSON(OS, TG);
+  printAsJSON(OS, TG, Storage);
 }
 
 ClangTidyProfiling::ClangTidyProfiling(std::optional<StorageParams> Storage)
@@ -85,7 +85,7 @@ ClangTidyProfiling::~ClangTidyProfiling() {
   if (!Storage)
     printUserFriendlyTable(llvm::errs(), TG);
   else
-    storeProfileData(TG);
+    storeProfileData(TG, *Storage);
 }
 
 } // namespace clang::tidy
diff --git a/clang-tools-extra/clang-tidy/ClangTidyProfiling.h 
b/clang-tools-extra/clang-tidy/ClangTidyProfiling.h
index 59c213b181ef7..40efcc10e2c47 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyProfiling.h
+++ b/clang-tools-extra/clang-tidy/ClangTidyProfiling.h
@@ -37,8 +37,9 @@ class ClangTidyProfiling {
   std::optional<StorageParams> Storage;
 
   void printUserFriendlyTable(llvm::raw_ostream &OS, llvm::TimerGroup &TG);
-  void printAsJSON(llvm::raw_ostream &OS, llvm::TimerGroup &TG);
-  void storeProfileData(llvm::TimerGroup &TG);
+  void printAsJSON(llvm::raw_ostream &OS, llvm::TimerGroup &TG,
+                   const StorageParams &Storage);
+  void storeProfileData(llvm::TimerGroup &TG, const StorageParams &Storage);
 
 public:
   llvm::StringMap<llvm::TimeRecord> Records;

>From 8f291da8d6fc14c6bbed07d64210d0bc427bf926 Mon Sep 17 00:00:00 2001
From: mtx <[email protected]>
Date: Sat, 29 Nov 2025 22:54:30 +0800
Subject: [PATCH 02/13] [clang-tidy] Fix bugprone-unchecked-optional-access in
 EasilySwappableParametersCheck

---
 .../clang-tidy/bugprone/EasilySwappableParametersCheck.cpp   | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git 
a/clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.cpp
index a07a68c8a3e65..bdc451be77c08 100644
--- a/clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.cpp
@@ -1690,8 +1690,9 @@ class PassedToSameFunction {
           TargetIdx.emplace(Idx);
 
       assert(TargetIdx && "Matched, but didn't find index?");
-      TargetParams[PassedParamOfThisFn].insert(
-          {CalledFn->getCanonicalDecl(), *TargetIdx});
+      if (TargetIdx)
+        TargetParams[PassedParamOfThisFn].insert(
+            {CalledFn->getCanonicalDecl(), *TargetIdx});
     }
   }
 

>From 83e4eff69af6d7705836a2f4c8a99a0165b7a97c Mon Sep 17 00:00:00 2001
From: mtx <[email protected]>
Date: Sat, 29 Nov 2025 22:58:04 +0800
Subject: [PATCH 03/13] [clang-tidy] Fix bugprone-unchecked-optional-access in
 IdentifierNamingCheck

---
 .../readability/IdentifierNamingCheck.cpp     | 26 ++++++++++++-------
 1 file changed, 16 insertions(+), 10 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
index d1583a62a8e5e..a4dda7e5e3285 100644
--- a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
@@ -440,7 +440,7 @@ bool 
IdentifierNamingCheck::HungarianNotation::isOptionEnabled(
   if (Iter == StrMap.end())
     return false;
 
-  return *llvm::yaml::parseBool(Iter->getValue());
+  return llvm::yaml::parseBool(Iter->getValue()).value_or(false);
 }
 
 void IdentifierNamingCheck::HungarianNotation::loadFileConfig(
@@ -834,26 +834,28 @@ void 
IdentifierNamingCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
   const ArrayRef<std::optional<NamingStyle>> Styles =
       MainFileStyle->getStyles();
   for (size_t I = 0; I < SK_Count; ++I) {
-    if (!Styles[I])
+    const auto &StyleOpt = Styles[I];
+    if (!StyleOpt)
       continue;
+    const NamingStyle &Style = *StyleOpt;
     const size_t StyleSize = StyleNames[I].size();
     StyleString.assign({StyleNames[I], "HungarianPrefix"});
 
-    Options.store(Opts, StyleString, Styles[I]->HPType);
+    Options.store(Opts, StyleString, Style.HPType);
 
     memcpy(&StyleString[StyleSize], "IgnoredRegexp", 13);
     StyleString.truncate(StyleSize + 13);
-    Options.store(Opts, StyleString, Styles[I]->IgnoredRegexpStr);
+    Options.store(Opts, StyleString, Style.IgnoredRegexpStr);
     memcpy(&StyleString[StyleSize], "Prefix", 6);
     StyleString.truncate(StyleSize + 6);
-    Options.store(Opts, StyleString, Styles[I]->Prefix);
+    Options.store(Opts, StyleString, Style.Prefix);
     // Fast replacement of [Pre]fix -> [Suf]fix.
     memcpy(&StyleString[StyleSize], "Suf", 3);
-    Options.store(Opts, StyleString, Styles[I]->Suffix);
-    if (Styles[I]->Case) {
+    Options.store(Opts, StyleString, Style.Suffix);
+    if (Style.Case) {
       memcpy(&StyleString[StyleSize], "Case", 4);
       StyleString.pop_back_n(2);
-      Options.store(Opts, StyleString, *Styles[I]->Case);
+      Options.store(Opts, StyleString, *Style.Case);
     }
   }
   Options.store(Opts, "GetConfigPerFile", GetConfigPerFile);
@@ -1344,10 +1346,14 @@ IdentifierNamingCheck::getFailureInfo(
     ArrayRef<std::optional<IdentifierNamingCheck::NamingStyle>> NamingStyles,
     const IdentifierNamingCheck::HungarianNotationOption &HNOption,
     StyleKind SK, const SourceManager &SM, bool IgnoreFailedSplit) const {
-  if (SK == SK_Invalid || !NamingStyles[SK])
+  if (SK == SK_Invalid)
     return std::nullopt;
 
-  const IdentifierNamingCheck::NamingStyle &Style = *NamingStyles[SK];
+  const auto &StyleOpt = NamingStyles[SK];
+  if (!StyleOpt)
+    return std::nullopt;
+
+  const IdentifierNamingCheck::NamingStyle &Style = *StyleOpt;
   if (Style.IgnoredRegexp.isValid() && Style.IgnoredRegexp.match(Name))
     return std::nullopt;
 

>From 395da7551951fb80ad18a4a1a67c5dec8f83e42d Mon Sep 17 00:00:00 2001
From: mtx <[email protected]>
Date: Sat, 29 Nov 2025 22:59:08 +0800
Subject: [PATCH 04/13] [clang-tidy] Fix bugprone-unchecked-optional-access in
 FunctionSizeCheck

---
 .../clang-tidy/readability/FunctionSizeCheck.cpp       | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/readability/FunctionSizeCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/FunctionSizeCheck.cpp
index 2f0949c231844..b80eed3f12971 100644
--- a/clang-tools-extra/clang-tidy/readability/FunctionSizeCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/FunctionSizeCheck.cpp
@@ -225,10 +225,12 @@ void FunctionSizeCheck::check(const 
MatchFinder::MatchResult &Result) {
         << ActualNumberParameters << ParameterThreshold.value();
   }
 
-  for (const auto &CSPos : FI.NestingThresholders) {
-    diag(CSPos, "nesting level %0 starts here (threshold %1)",
-         DiagnosticIDs::Note)
-        << NestingThreshold.value() + 1 << NestingThreshold.value();
+  if (NestingThreshold) {
+    for (const auto &CSPos : FI.NestingThresholders) {
+      diag(CSPos, "nesting level %0 starts here (threshold %1)",
+           DiagnosticIDs::Note)
+          << NestingThreshold.value() + 1 << NestingThreshold.value();
+    }
   }
 
   if (VariableThreshold && FI.Variables > VariableThreshold) {

>From f6677ba346b91fcf18f4f9950ca305b4c34a4ab3 Mon Sep 17 00:00:00 2001
From: mtx <[email protected]>
Date: Sat, 29 Nov 2025 23:00:11 +0800
Subject: [PATCH 05/13] [clang-tidy] Fix bugprone-unchecked-optional-access in
 ExceptionAnalyzer

---
 clang-tools-extra/clang-tidy/utils/ExceptionAnalyzer.cpp | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/clang-tools-extra/clang-tidy/utils/ExceptionAnalyzer.cpp 
b/clang-tools-extra/clang-tidy/utils/ExceptionAnalyzer.cpp
index f766a1bca655c..428e3822c78c6 100644
--- a/clang-tools-extra/clang-tidy/utils/ExceptionAnalyzer.cpp
+++ b/clang-tools-extra/clang-tidy/utils/ExceptionAnalyzer.cpp
@@ -304,6 +304,9 @@ static bool isQualificationConvertiblePointer(QualType 
From, QualType To,
            "From pointer or array has no pointee or element!");
     assert(ToPointeeOrElem && "To pointer or array has no pointee or 
element!");
 
+    if (!FromPointeeOrElem || !ToPointeeOrElem)
+      return false;
+
     From = *FromPointeeOrElem;
     To = *ToPointeeOrElem;
   }

>From 4f0c34264df35ac61967c8acfae94a27af3ce047 Mon Sep 17 00:00:00 2001
From: mtx <[email protected]>
Date: Sat, 29 Nov 2025 23:00:59 +0800
Subject: [PATCH 06/13] [clang-tidy] Fix bugprone-unchecked-optional-access in
 TimeSubtractionCheck

---
 clang-tools-extra/clang-tidy/abseil/TimeSubtractionCheck.cpp | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/clang-tools-extra/clang-tidy/abseil/TimeSubtractionCheck.cpp 
b/clang-tools-extra/clang-tidy/abseil/TimeSubtractionCheck.cpp
index 4ae49d285930d..b23b6ad25a23c 100644
--- a/clang-tools-extra/clang-tidy/abseil/TimeSubtractionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/abseil/TimeSubtractionCheck.cpp
@@ -96,6 +96,8 @@ void TimeSubtractionCheck::registerMatchers(MatchFinder 
*Finder) {
     const std::string TimeInverse = (llvm::Twine("ToUnix") + ScaleName).str();
     std::optional<DurationScale> Scale = getScaleForTimeInverse(TimeInverse);
     assert(Scale && "Unknown scale encountered");
+    if (!Scale)
+      continue;
 
     auto TimeInverseMatcher = callExpr(callee(
         functionDecl(hasName((llvm::Twine("::absl::") + TimeInverse).str()))

>From 7f6239f19a809f8ed9623d651942d819d1498bc7 Mon Sep 17 00:00:00 2001
From: mtx <[email protected]>
Date: Sat, 29 Nov 2025 23:08:27 +0800
Subject: [PATCH 07/13] [clang-tidy] Fix bugprone-unchecked-optional-access in
 ClangTidyDiagnosticConsumer

---
 .../ClangTidyDiagnosticConsumer.cpp           | 21 +++++++++++--------
 1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp 
b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
index 6716d90a1acaf..7198dd5bb8546 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
@@ -239,13 +239,16 @@ static bool 
parseFileExtensions(llvm::ArrayRef<std::string> AllFileExtensions,
 void ClangTidyContext::setCurrentFile(StringRef File) {
   CurrentFile = std::string(File);
   CurrentOptions = getOptionsForFile(CurrentFile);
-  CheckFilter = std::make_unique<CachedGlobList>(*getOptions().Checks);
-  WarningAsErrorFilter =
-      std::make_unique<CachedGlobList>(*getOptions().WarningsAsErrors);
-  if (!parseFileExtensions(*getOptions().HeaderFileExtensions,
+  CheckFilter =
+      std::make_unique<CachedGlobList>(getOptions().Checks.value_or(""));
+  WarningAsErrorFilter = std::make_unique<CachedGlobList>(
+      getOptions().WarningsAsErrors.value_or(""));
+  if (!parseFileExtensions(getOptions().HeaderFileExtensions.value_or(
+                               std::vector<std::string>()),
                            HeaderFileExtensions))
     this->configurationDiag("Invalid header file extensions");
-  if (!parseFileExtensions(*getOptions().ImplementationFileExtensions,
+  if (!parseFileExtensions(getOptions().ImplementationFileExtensions.value_or(
+                               std::vector<std::string>()),
                            ImplementationFileExtensions))
     this->configurationDiag("Invalid implementation file extensions");
 }
@@ -569,7 +572,7 @@ void 
ClangTidyDiagnosticConsumer::checkFilters(SourceLocation Location,
     return;
   }
 
-  if (!*Context.getOptions().SystemHeaders &&
+  if (!Context.getOptions().SystemHeaders.value_or(false) &&
       (Sources.isInSystemHeader(Location) || 
Sources.isInSystemMacro(Location)))
     return;
 
@@ -600,15 +603,15 @@ void 
ClangTidyDiagnosticConsumer::checkFilters(SourceLocation Location,
 
 llvm::Regex *ClangTidyDiagnosticConsumer::getHeaderFilter() {
   if (!HeaderFilter)
-    HeaderFilter =
-        std::make_unique<llvm::Regex>(*Context.getOptions().HeaderFilterRegex);
+    HeaderFilter = std::make_unique<llvm::Regex>(
+        Context.getOptions().HeaderFilterRegex.value_or(""));
   return HeaderFilter.get();
 }
 
 llvm::Regex *ClangTidyDiagnosticConsumer::getExcludeHeaderFilter() {
   if (!ExcludeHeaderFilter)
     ExcludeHeaderFilter = std::make_unique<llvm::Regex>(
-        *Context.getOptions().ExcludeHeaderFilterRegex);
+        Context.getOptions().ExcludeHeaderFilterRegex.value_or(""));
   return ExcludeHeaderFilter.get();
 }
 

>From b1eeb0517e1107131811f20faf9001a3a5585b6d Mon Sep 17 00:00:00 2001
From: mtx <[email protected]>
Date: Sat, 29 Nov 2025 23:09:15 +0800
Subject: [PATCH 08/13] [clang-tidy] Fix bugprone-unchecked-optional-access in
 UseRangesCheck

---
 clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp 
b/clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp
index 09adbf1155e62..5cd88a72e83e1 100644
--- a/clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp
+++ b/clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp
@@ -247,6 +247,8 @@ void UseRangesCheck::check(const MatchFinder::MatchResult 
&Result) {
                 Result.Context->getLangOpts()));
       } else {
         assert(ReverseDescriptor && "Couldn't find forward argument");
+        if (!ReverseDescriptor)
+          return;
         ArgNode.push_back('R');
         ArgExpr = Result.Nodes.getNodeAs<Expr>(ArgNode);
         assert(ArgExpr && "Couldn't find forward or reverse argument");

>From d5e3c033486e1ca4f7ab883cb6f8a34f8598fa80 Mon Sep 17 00:00:00 2001
From: mtx <[email protected]>
Date: Sat, 29 Nov 2025 23:10:38 +0800
Subject: [PATCH 09/13] [clang-tidy] Fix bugprone-unchecked-optional-access in
 RedundantBranchConditionCheck

---
 .../RedundantBranchConditionCheck.cpp         | 36 ++++++++++---------
 1 file changed, 19 insertions(+), 17 deletions(-)

diff --git 
a/clang-tools-extra/clang-tidy/bugprone/RedundantBranchConditionCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/RedundantBranchConditionCheck.cpp
index 528c254dbe17e..8eced3ee61c33 100644
--- a/clang-tools-extra/clang-tidy/bugprone/RedundantBranchConditionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/RedundantBranchConditionCheck.cpp
@@ -132,17 +132,18 @@ void RedundantBranchConditionCheck::check(
 
     // If the other side has side effects then keep it.
     if (OtherSide && OtherSide->HasSideEffects(*Result.Context)) {
-      const SourceLocation BeforeOtherSide =
-          OtherSide->getBeginLoc().getLocWithOffset(-1);
-      const SourceLocation AfterOtherSide =
-          Lexer::findNextToken(OtherSide->getEndLoc(), *Result.SourceManager,
-                               getLangOpts())
-              ->getLocation();
-      Diag << FixItHint::CreateRemoval(
-                  CharSourceRange::getTokenRange(IfBegin, BeforeOtherSide))
-           << FixItHint::CreateInsertion(AfterOtherSide, ";")
-           << FixItHint::CreateRemoval(
-                  CharSourceRange::getTokenRange(AfterOtherSide, IfEnd));
+      auto NextToken = Lexer::findNextToken(
+          OtherSide->getEndLoc(), *Result.SourceManager, getLangOpts());
+      if (NextToken) {
+        const SourceLocation BeforeOtherSide =
+            OtherSide->getBeginLoc().getLocWithOffset(-1);
+        const SourceLocation AfterOtherSide = NextToken->getLocation();
+        Diag << FixItHint::CreateRemoval(
+                    CharSourceRange::getTokenRange(IfBegin, BeforeOtherSide))
+             << FixItHint::CreateInsertion(AfterOtherSide, ";")
+             << FixItHint::CreateRemoval(
+                    CharSourceRange::getTokenRange(AfterOtherSide, IfEnd));
+      }
     } else {
       Diag << FixItHint::CreateRemoval(
           CharSourceRange::getTokenRange(IfBegin, IfEnd));
@@ -166,12 +167,13 @@ void RedundantBranchConditionCheck::check(
       Diag << FixItHint::CreateRemoval(CharSourceRange::getTokenRange(
           CondOp->getLHS()->getBeginLoc(), BeforeRHS));
     } else {
-      const SourceLocation AfterLHS =
-          Lexer::findNextToken(CondOp->getLHS()->getEndLoc(),
-                               *Result.SourceManager, getLangOpts())
-              ->getLocation();
-      Diag << FixItHint::CreateRemoval(CharSourceRange::getTokenRange(
-          AfterLHS, CondOp->getRHS()->getEndLoc()));
+      auto NextToken = Lexer::findNextToken(
+          CondOp->getLHS()->getEndLoc(), *Result.SourceManager, getLangOpts());
+      if (NextToken) {
+        const SourceLocation AfterLHS = NextToken->getLocation();
+        Diag << FixItHint::CreateRemoval(CharSourceRange::getTokenRange(
+            AfterLHS, CondOp->getRHS()->getEndLoc()));
+      }
     }
   }
 }

>From eabda175aad16af8cb13812741dcb815aa3b1db6 Mon Sep 17 00:00:00 2001
From: mtx <[email protected]>
Date: Sat, 29 Nov 2025 23:11:28 +0800
Subject: [PATCH 10/13] [clang-tidy] Fix bugprone-unchecked-optional-access in
 ClangTidy.cpp

---
 clang-tools-extra/clang-tidy/ClangTidy.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/clang-tools-extra/clang-tidy/ClangTidy.cpp 
b/clang-tools-extra/clang-tidy/ClangTidy.cpp
index 4af328cd5110a..e2f581562e97d 100644
--- a/clang-tools-extra/clang-tidy/ClangTidy.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidy.cpp
@@ -213,7 +213,8 @@ class ErrorReporter {
         }
         const StringRef Code = Buffer.get()->getBuffer();
         auto Style = format::getStyle(
-            *Context.getOptionsForFile(File).FormatStyle, File, "none");
+            Context.getOptionsForFile(File).FormatStyle.value_or("none"), File,
+            "none");
         if (!Style) {
           llvm::errs() << llvm::toString(Style.takeError()) << "\n";
           continue;

>From 4fd99891b3a6ef254a664a4382c128eaca9fca82 Mon Sep 17 00:00:00 2001
From: mtx <[email protected]>
Date: Sat, 29 Nov 2025 23:13:18 +0800
Subject: [PATCH 11/13] [clang-tidy] Fix bugprone-unchecked-optional-access in
 FormatStringConverter

---
 .../clang-tidy/utils/FormatStringConverter.cpp            | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/utils/FormatStringConverter.cpp 
b/clang-tools-extra/clang-tidy/utils/FormatStringConverter.cpp
index d210b000dfd33..ab830d8d455d9 100644
--- a/clang-tools-extra/clang-tidy/utils/FormatStringConverter.cpp
+++ b/clang-tools-extra/clang-tidy/utils/FormatStringConverter.cpp
@@ -800,9 +800,11 @@ void FormatStringConverter::applyFixes(DiagnosticBuilder 
&Diag,
   }
 
   for (const auto &[ArgIndex, Replacement] : ArgFixes) {
-    const SourceLocation AfterOtherSide =
-        Lexer::findNextToken(Args[ArgIndex]->getEndLoc(), SM, LangOpts)
-            ->getLocation();
+    const auto NextToken =
+        Lexer::findNextToken(Args[ArgIndex]->getEndLoc(), SM, LangOpts);
+    if (!NextToken)
+      continue;
+    const SourceLocation AfterOtherSide = NextToken->getLocation();
 
     Diag << FixItHint::CreateInsertion(Args[ArgIndex]->getBeginLoc(),
                                        Replacement, true)

>From a9d0e38f431f6981acfd44cbcbf59ffbde51516e Mon Sep 17 00:00:00 2001
From: mtx <[email protected]>
Date: Sat, 29 Nov 2025 23:26:15 +0800
Subject: [PATCH 12/13] [clang-tidy] Enable bugprone-unchecked-optional-access

---
 clang-tools-extra/clang-tidy/.clang-tidy | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang-tools-extra/clang-tidy/.clang-tidy 
b/clang-tools-extra/clang-tidy/.clang-tidy
index 82d0df8697178..26dfeb4a1f743 100644
--- a/clang-tools-extra/clang-tidy/.clang-tidy
+++ b/clang-tools-extra/clang-tidy/.clang-tidy
@@ -7,7 +7,7 @@ Checks: >
   -bugprone-branch-clone,
   -bugprone-easily-swappable-parameters,
   -bugprone-narrowing-conversions,
-  -bugprone-unchecked-optional-access,
+  bugprone-unchecked-optional-access,
   -bugprone-unused-return-value,
   misc-const-correctness,
   modernize-*,

>From 26d1aa75fabd4dd103e28ec495c1f5dc5ab305bf Mon Sep 17 00:00:00 2001
From: mtx <[email protected]>
Date: Sun, 30 Nov 2025 00:01:54 +0800
Subject: [PATCH 13/13] Revert "[clang-tidy] Fix
 bugprone-unchecked-optional-access in ClangTidyDiagnosticConsumer"

This reverts commit 7f6239f19a809f8ed9623d651942d819d1498bc7.
---
 .../ClangTidyDiagnosticConsumer.cpp           | 21 ++++++++-----------
 1 file changed, 9 insertions(+), 12 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp 
b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
index 7198dd5bb8546..6716d90a1acaf 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
@@ -239,16 +239,13 @@ static bool 
parseFileExtensions(llvm::ArrayRef<std::string> AllFileExtensions,
 void ClangTidyContext::setCurrentFile(StringRef File) {
   CurrentFile = std::string(File);
   CurrentOptions = getOptionsForFile(CurrentFile);
-  CheckFilter =
-      std::make_unique<CachedGlobList>(getOptions().Checks.value_or(""));
-  WarningAsErrorFilter = std::make_unique<CachedGlobList>(
-      getOptions().WarningsAsErrors.value_or(""));
-  if (!parseFileExtensions(getOptions().HeaderFileExtensions.value_or(
-                               std::vector<std::string>()),
+  CheckFilter = std::make_unique<CachedGlobList>(*getOptions().Checks);
+  WarningAsErrorFilter =
+      std::make_unique<CachedGlobList>(*getOptions().WarningsAsErrors);
+  if (!parseFileExtensions(*getOptions().HeaderFileExtensions,
                            HeaderFileExtensions))
     this->configurationDiag("Invalid header file extensions");
-  if (!parseFileExtensions(getOptions().ImplementationFileExtensions.value_or(
-                               std::vector<std::string>()),
+  if (!parseFileExtensions(*getOptions().ImplementationFileExtensions,
                            ImplementationFileExtensions))
     this->configurationDiag("Invalid implementation file extensions");
 }
@@ -572,7 +569,7 @@ void 
ClangTidyDiagnosticConsumer::checkFilters(SourceLocation Location,
     return;
   }
 
-  if (!Context.getOptions().SystemHeaders.value_or(false) &&
+  if (!*Context.getOptions().SystemHeaders &&
       (Sources.isInSystemHeader(Location) || 
Sources.isInSystemMacro(Location)))
     return;
 
@@ -603,15 +600,15 @@ void 
ClangTidyDiagnosticConsumer::checkFilters(SourceLocation Location,
 
 llvm::Regex *ClangTidyDiagnosticConsumer::getHeaderFilter() {
   if (!HeaderFilter)
-    HeaderFilter = std::make_unique<llvm::Regex>(
-        Context.getOptions().HeaderFilterRegex.value_or(""));
+    HeaderFilter =
+        std::make_unique<llvm::Regex>(*Context.getOptions().HeaderFilterRegex);
   return HeaderFilter.get();
 }
 
 llvm::Regex *ClangTidyDiagnosticConsumer::getExcludeHeaderFilter() {
   if (!ExcludeHeaderFilter)
     ExcludeHeaderFilter = std::make_unique<llvm::Regex>(
-        Context.getOptions().ExcludeHeaderFilterRegex.value_or(""));
+        *Context.getOptions().ExcludeHeaderFilterRegex);
   return ExcludeHeaderFilter.get();
 }
 

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

Reply via email to