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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions clang/include/clang/Basic/SanitizerSpecialCaseList.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion clang/lib/Basic/NoSanitizeList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 7 additions & 2 deletions clang/lib/Basic/SanitizerSpecialCaseList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Comment on lines +38 to +39
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't be a custom diagnostic; I would imagine this would be a driver diagnostic. But we can't emit driver diagnostics from Basic.

I think we need a bit wider of an approach where createOrDie is create which the caller has to respond to if it returns an empty unique_ptr so that the driver eventually is what emits the diagnostic.

CC @MaskRay for more opinions

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MaskRay Do you have any thoughts on this approach? Would appreciate your input.


Diags.Report(DiagID) << Error;
exit(1);
}

void SanitizerSpecialCaseList::createSanitizerSections() {
Expand Down
7 changes: 7 additions & 0 deletions clang/test/Driver/fsanitize-ignorelist.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 {{.*[\\/]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: