https://github.com/woruyu updated https://github.com/llvm/llvm-project/pull/147959
>From e18ed1ac787a0571318b8cfe1d4eee023ba11fc2 Mon Sep 17 00:00:00 2001 From: woruyu <1214539...@qq.com> Date: Thu, 10 Jul 2025 21:08:24 +0800 Subject: [PATCH 1/4] fix: replace report_fatal_error with Diags and exit --- clang/include/clang/Basic/SanitizerSpecialCaseList.h | 5 +++-- clang/lib/Basic/NoSanitizeList.cpp | 3 ++- clang/lib/Basic/SanitizerSpecialCaseList.cpp | 9 +++++++-- 3 files changed, 12 insertions(+), 5 deletions(-) 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() { >From d90381c2ff9cc11ff3df9e513efa5e69db3c66d8 Mon Sep 17 00:00:00 2001 From: woruyu <1214539...@qq.com> Date: Fri, 11 Jul 2025 10:29:01 +0800 Subject: [PATCH 2/4] add testcase --- clang/test/Driver/fsanitize-ignorelist.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/clang/test/Driver/fsanitize-ignorelist.c b/clang/test/Driver/fsanitize-ignorelist.c index 7dd666a453198..9cb56900bd2a4 100644 --- a/clang/test/Driver/fsanitize-ignorelist.c +++ b/clang/test/Driver/fsanitize-ignorelist.c @@ -71,3 +71,10 @@ // CHECK-MISSING-CFI-NO-IGNORELIST-NOT: error: no such file or directory: '{{.*}}cfi_ignorelist.txt' // DELIMITERS: {{^ *"}} + +// Check that a missing file passed to -fsanitize-system-ignorelist triggers a clean error without crashing. +// RUN: not %clang --target=x86_64-linux-gnu -Xclang -fsanitize-system-ignorelist=%t.nonexistent %s -c -o /dev/null 2>&1 | FileCheck %s --check-prefix=CHECK-SYSTEM-IGNORELIST-NOFILE +// CHECK-SYSTEM-IGNORELIST-NOFILE: error: failed to load NoSanitize file: can't open file '{{.*}}.nonexistent': No such file or directory +// CHECK-SYSTEM-IGNORELIST-NOFILE-NOT: Stack dump: +// CHECK-SYSTEM-IGNORELIST-NOFILE-NOT: PLEASE submit a bug report +// CHECK-SYSTEM-IGNORELIST-NOFILE-NOT: diagnostic msg: >From 4920812618f8d1fbb3179dc26c42d1a0467da789 Mon Sep 17 00:00:00 2001 From: woruyu <1214539...@qq.com> Date: Fri, 11 Jul 2025 11:30:53 +0800 Subject: [PATCH 3/4] fix: windows test error --- clang/test/Driver/fsanitize-ignorelist.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/test/Driver/fsanitize-ignorelist.c b/clang/test/Driver/fsanitize-ignorelist.c index 9cb56900bd2a4..c758b1b24e2a7 100644 --- a/clang/test/Driver/fsanitize-ignorelist.c +++ b/clang/test/Driver/fsanitize-ignorelist.c @@ -74,7 +74,7 @@ // Check that a missing file passed to -fsanitize-system-ignorelist triggers a clean error without crashing. // RUN: not %clang --target=x86_64-linux-gnu -Xclang -fsanitize-system-ignorelist=%t.nonexistent %s -c -o /dev/null 2>&1 | FileCheck %s --check-prefix=CHECK-SYSTEM-IGNORELIST-NOFILE -// CHECK-SYSTEM-IGNORELIST-NOFILE: error: failed to load NoSanitize file: can't open file '{{.*}}.nonexistent': No such file or directory +// CHECK-SYSTEM-IGNORELIST-NOFILE: error: failed to load NoSanitize file: can't open file {{.*[\\/]fsanitize-ignorelist\.c\.tmp\.nonexistent}} // CHECK-SYSTEM-IGNORELIST-NOFILE-NOT: Stack dump: // CHECK-SYSTEM-IGNORELIST-NOFILE-NOT: PLEASE submit a bug report // CHECK-SYSTEM-IGNORELIST-NOFILE-NOT: diagnostic msg: >From 17c4ae7c891371f93ecd2269bd5b20efe9fcdff8 Mon Sep 17 00:00:00 2001 From: woruyu <1214539...@qq.com> Date: Mon, 21 Jul 2025 12:53:59 +0800 Subject: [PATCH 4/4] fix: review --- clang/include/clang/AST/ASTContext.h | 2 ++ clang/include/clang/Basic/NoSanitizeList.h | 4 ++-- .../include/clang/Basic/SanitizerSpecialCaseList.h | 4 ---- clang/lib/AST/ASTContext.cpp | 12 +++++++++++- clang/lib/Basic/NoSanitizeList.cpp | 14 ++++++++------ clang/lib/Basic/SanitizerSpecialCaseList.cpp | 14 -------------- clang/lib/Frontend/CompilerInstance.cpp | 1 + clang/test/Driver/fsanitize-ignorelist.c | 2 +- 8 files changed, 25 insertions(+), 28 deletions(-) diff --git a/clang/include/clang/AST/ASTContext.h b/clang/include/clang/AST/ASTContext.h index 2b9cd035623cc..7584999b3f66e 100644 --- a/clang/include/clang/AST/ASTContext.h +++ b/clang/include/clang/AST/ASTContext.h @@ -629,6 +629,8 @@ class ASTContext : public RefCountedBase<ASTContext> { void setRelocationInfoForCXXRecord(const CXXRecordDecl *, CXXRecordDeclRelocationInfo); + void initSanitizers(const LangOptions &LangOpts, SourceManager &SM); + /// Examines a given type, and returns whether the type itself /// is address discriminated, or any transitively embedded types /// contain data that is address discriminated. This includes diff --git a/clang/include/clang/Basic/NoSanitizeList.h b/clang/include/clang/Basic/NoSanitizeList.h index a7a7a29d50a9a..b99e05a3bfdb1 100644 --- a/clang/include/clang/Basic/NoSanitizeList.h +++ b/clang/include/clang/Basic/NoSanitizeList.h @@ -33,9 +33,9 @@ class NoSanitizeList { StringRef Category) const; public: - NoSanitizeList(const std::vector<std::string> &NoSanitizeListPaths, - SourceManager &SM); + NoSanitizeList(SourceManager &SM); ~NoSanitizeList(); + bool init(const std::vector<std::string> &Paths, std::string &Error); bool containsGlobal(SanitizerMask Mask, StringRef GlobalName, StringRef Category = StringRef()) const; bool containsType(SanitizerMask Mask, StringRef MangledTypeName, diff --git a/clang/include/clang/Basic/SanitizerSpecialCaseList.h b/clang/include/clang/Basic/SanitizerSpecialCaseList.h index 72cdcf7c467f0..1670e37a1c6ca 100644 --- a/clang/include/clang/Basic/SanitizerSpecialCaseList.h +++ b/clang/include/clang/Basic/SanitizerSpecialCaseList.h @@ -37,10 +37,6 @@ class SanitizerSpecialCaseList : public llvm::SpecialCaseList { create(const std::vector<std::string> &Paths, llvm::vfs::FileSystem &VFS, std::string &Error); - static std::unique_ptr<SanitizerSpecialCaseList> - 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, StringRef Category = StringRef()) const; diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index 679812adcdf12..70a7366e1ff54 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -50,6 +50,7 @@ #include "clang/Basic/AddressSpaces.h" #include "clang/Basic/Builtins.h" #include "clang/Basic/CommentOptions.h" +#include "clang/Basic/DiagnosticFrontend.h" #include "clang/Basic/ExceptionSpecificationType.h" #include "clang/Basic/IdentifierTable.h" #include "clang/Basic/LLVM.h" @@ -944,7 +945,7 @@ ASTContext::ASTContext(LangOptions &LOpts, SourceManager &SM, DependentBitIntTypes(this_()), SubstTemplateTemplateParmPacks(this_()), DeducedTemplates(this_()), ArrayParameterTypes(this_()), CanonTemplateTemplateParms(this_()), SourceMgr(SM), LangOpts(LOpts), - NoSanitizeL(new NoSanitizeList(LangOpts.NoSanitizeFiles, SM)), + NoSanitizeL(new NoSanitizeList(SM)), XRayFilter(new XRayFunctionFilter(LangOpts.XRayAlwaysInstrumentFiles, LangOpts.XRayNeverInstrumentFiles, LangOpts.XRayAttrListFiles, SM)), @@ -1697,6 +1698,15 @@ ASTContext::getRelocationInfoForCXXRecord(const CXXRecordDecl *RD) const { return std::nullopt; } +void ASTContext::initSanitizers(const LangOptions &LangOpts, + SourceManager &SM) { + std::string Error; + if (!NoSanitizeL->init(LangOpts.NoSanitizeFiles, Error)) { + const std::string &Path = LangOpts.NoSanitizeFiles.front(); + SM.getDiagnostics().Report(diag::err_fe_error_reading) << Path << Error; + } +} + void ASTContext::setRelocationInfoForCXXRecord( const CXXRecordDecl *RD, CXXRecordDeclRelocationInfo Info) { assert(RD); diff --git a/clang/lib/Basic/NoSanitizeList.cpp b/clang/lib/Basic/NoSanitizeList.cpp index 1ae304fbd2132..c857065684820 100644 --- a/clang/lib/Basic/NoSanitizeList.cpp +++ b/clang/lib/Basic/NoSanitizeList.cpp @@ -19,12 +19,7 @@ using namespace clang; -NoSanitizeList::NoSanitizeList(const std::vector<std::string> &NoSanitizePaths, - SourceManager &SM) - : SSCL(SanitizerSpecialCaseList::createOrDie( - NoSanitizePaths, SM.getFileManager().getVirtualFileSystem(), - SM.getDiagnostics())), - SM(SM) {} +NoSanitizeList::NoSanitizeList(SourceManager &SM) : SM(SM) {} NoSanitizeList::~NoSanitizeList() = default; @@ -43,6 +38,13 @@ bool NoSanitizeList::containsPrefix(SanitizerMask Mask, StringRef Prefix, return San == llvm::SpecialCaseList::NotFound || NoSan > San; } +bool NoSanitizeList::init(const std::vector<std::string> &Paths, + std::string &Error) { + SSCL = SanitizerSpecialCaseList::create( + Paths, SM.getFileManager().getVirtualFileSystem(), Error); + return SSCL != nullptr; +} + bool NoSanitizeList::containsGlobal(SanitizerMask Mask, StringRef GlobalName, StringRef Category) const { return containsPrefix(Mask, "global", GlobalName, Category); diff --git a/clang/lib/Basic/SanitizerSpecialCaseList.cpp b/clang/lib/Basic/SanitizerSpecialCaseList.cpp index 51a09b341f495..ade3b52239e92 100644 --- a/clang/lib/Basic/SanitizerSpecialCaseList.cpp +++ b/clang/lib/Basic/SanitizerSpecialCaseList.cpp @@ -28,20 +28,6 @@ SanitizerSpecialCaseList::create(const std::vector<std::string> &Paths, return nullptr; } -std::unique_ptr<SanitizerSpecialCaseList> -SanitizerSpecialCaseList::createOrDie(const std::vector<std::string> &Paths, - llvm::vfs::FileSystem &VFS, - DiagnosticsEngine &Diags) { - std::string Error; - if (auto SSCL = create(Paths, VFS, Error)) - return SSCL; - unsigned DiagID = Diags.getCustomDiagID(clang::DiagnosticsEngine::Error, - "failed to load NoSanitize file: %0"); - - Diags.Report(DiagID) << Error; - exit(1); -} - void SanitizerSpecialCaseList::createSanitizerSections() { for (auto &S : Sections) { SanitizerMask Mask; diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp index 6f8cc01eeed88..4e34cf507f22a 100644 --- a/clang/lib/Frontend/CompilerInstance.cpp +++ b/clang/lib/Frontend/CompilerInstance.cpp @@ -554,6 +554,7 @@ void CompilerInstance::createASTContext() { PP.getBuiltinInfo(), PP.TUKind); Context->InitBuiltinTypes(getTarget(), getAuxTarget()); setASTContext(Context); + Context->initSanitizers(getLangOpts(), PP.getSourceManager()); } // ExternalASTSource diff --git a/clang/test/Driver/fsanitize-ignorelist.c b/clang/test/Driver/fsanitize-ignorelist.c index c758b1b24e2a7..c00b5bf433def 100644 --- a/clang/test/Driver/fsanitize-ignorelist.c +++ b/clang/test/Driver/fsanitize-ignorelist.c @@ -74,7 +74,7 @@ // Check that a missing file passed to -fsanitize-system-ignorelist triggers a clean error without crashing. // RUN: not %clang --target=x86_64-linux-gnu -Xclang -fsanitize-system-ignorelist=%t.nonexistent %s -c -o /dev/null 2>&1 | FileCheck %s --check-prefix=CHECK-SYSTEM-IGNORELIST-NOFILE -// CHECK-SYSTEM-IGNORELIST-NOFILE: error: failed to load NoSanitize file: can't open file {{.*[\\/]fsanitize-ignorelist\.c\.tmp\.nonexistent}} +// CHECK-SYSTEM-IGNORELIST-NOFILE: error: error reading '{{.*[\\/]fsanitize-ignorelist\.c\.tmp\.nonexistent}}': can't open file '{{.*[\\/]fsanitize-ignorelist\.c\.tmp\.nonexistent}}': {{[Nn]o such file or directory}} // CHECK-SYSTEM-IGNORELIST-NOFILE-NOT: Stack dump: // CHECK-SYSTEM-IGNORELIST-NOFILE-NOT: PLEASE submit a bug report // CHECK-SYSTEM-IGNORELIST-NOFILE-NOT: diagnostic msg: _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits