Skip to content

fix: replace report_fatal_error with Diags and exit #147959

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

woruyu
Copy link
Contributor

@woruyu woruyu commented Jul 10, 2025

Summary
This PR resolves #147187

@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Jul 10, 2025
@llvmbot
Copy link
Member

llvmbot commented Jul 10, 2025

@llvm/pr-subscribers-clang-driver

@llvm/pr-subscribers-clang

Author: woruyu (woruyu)

Changes

Summary
This PR resolves #147187


Full diff: https://github.com/llvm/llvm-project/pull/147959.diff

3 Files Affected:

  • (modified) clang/include/clang/Basic/SanitizerSpecialCaseList.h (+3-2)
  • (modified) clang/lib/Basic/NoSanitizeList.cpp (+2-1)
  • (modified) clang/lib/Basic/SanitizerSpecialCaseList.cpp (+7-2)
diff --git a/clang/include/clang/Basic/SanitizerSpecialCaseList.h b/clang/include/clang/Basic/SanitizerSpecialCaseList.h
index cf7485909e409..72cdcf7c467f0 100644
--- a/clang/include/clang/Basic/SanitizerSpecialCaseList.h
+++ b/clang/include/clang/Basic/SanitizerSpecialCaseList.h
@@ -14,6 +14,7 @@
 #ifndef LLVM_CLANG_BASIC_SANITIZERSPECIALCASELIST_H
 #define LLVM_CLANG_BASIC_SANITIZERSPECIALCASELIST_H
 
+#include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/LLVM.h"
 #include "clang/Basic/Sanitizers.h"
 #include "llvm/ADT/StringRef.h"
@@ -37,8 +38,8 @@ class SanitizerSpecialCaseList : public llvm::SpecialCaseList {
          std::string &Error);
 
   static std::unique_ptr<SanitizerSpecialCaseList>
-  createOrDie(const std::vector<std::string> &Paths,
-              llvm::vfs::FileSystem &VFS);
+  createOrDie(const std::vector<std::string> &Paths, llvm::vfs::FileSystem &VFS,
+              DiagnosticsEngine &Diags);
 
   // Query ignorelisted entries if any bit in Mask matches the entry's section.
   bool inSection(SanitizerMask Mask, StringRef Prefix, StringRef Query,
diff --git a/clang/lib/Basic/NoSanitizeList.cpp b/clang/lib/Basic/NoSanitizeList.cpp
index 96f79fb2a2a29..1ae304fbd2132 100644
--- a/clang/lib/Basic/NoSanitizeList.cpp
+++ b/clang/lib/Basic/NoSanitizeList.cpp
@@ -22,7 +22,8 @@ using namespace clang;
 NoSanitizeList::NoSanitizeList(const std::vector<std::string> &NoSanitizePaths,
                                SourceManager &SM)
     : SSCL(SanitizerSpecialCaseList::createOrDie(
-          NoSanitizePaths, SM.getFileManager().getVirtualFileSystem())),
+          NoSanitizePaths, SM.getFileManager().getVirtualFileSystem(),
+          SM.getDiagnostics())),
       SM(SM) {}
 
 NoSanitizeList::~NoSanitizeList() = default;
diff --git a/clang/lib/Basic/SanitizerSpecialCaseList.cpp b/clang/lib/Basic/SanitizerSpecialCaseList.cpp
index f7bc1d5545d75..51a09b341f495 100644
--- a/clang/lib/Basic/SanitizerSpecialCaseList.cpp
+++ b/clang/lib/Basic/SanitizerSpecialCaseList.cpp
@@ -30,11 +30,16 @@ SanitizerSpecialCaseList::create(const std::vector<std::string> &Paths,
 
 std::unique_ptr<SanitizerSpecialCaseList>
 SanitizerSpecialCaseList::createOrDie(const std::vector<std::string> &Paths,
-                                      llvm::vfs::FileSystem &VFS) {
+                                      llvm::vfs::FileSystem &VFS,
+                                      DiagnosticsEngine &Diags) {
   std::string Error;
   if (auto SSCL = create(Paths, VFS, Error))
     return SSCL;
-  llvm::report_fatal_error(StringRef(Error));
+  unsigned DiagID = Diags.getCustomDiagID(clang::DiagnosticsEngine::Error,
+                                          "failed to load NoSanitize file: %0");
+
+  Diags.Report(DiagID) << Error;
+  exit(1);
 }
 
 void SanitizerSpecialCaseList::createSanitizerSections() {

@woruyu
Copy link
Contributor Author

woruyu commented Jul 10, 2025

@hstk30-hw This patch is now ready for review.

@hstk30-hw
Copy link
Contributor

Need a test case at least.

@llvmbot llvmbot added the clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' label Jul 11, 2025
@woruyu
Copy link
Contributor Author

woruyu commented Jul 11, 2025

Need a test case at least.

Done!

@hstk30-hw
Copy link
Contributor

@shafik Take a look, pls.

@woruyu woruyu force-pushed the fix/report-error-sanitize-file branch from 816fe1e to a4236f9 Compare July 11, 2025 03:50
@woruyu woruyu force-pushed the fix/report-error-sanitize-file branch from a4236f9 to 4920812 Compare July 11, 2025 06:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Clang-21 Crash: fatal error: error in backend: can't open file './xxxxxx': No such file or directory
3 participants