-
Notifications
You must be signed in to change notification settings - Fork 14.5k
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
base: main
Are you sure you want to change the base?
Conversation
@llvm/pr-subscribers-clang-driver @llvm/pr-subscribers-clang Author: woruyu (woruyu) ChangesSummary Full diff: https://github.com/llvm/llvm-project/pull/147959.diff 3 Files Affected:
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() {
|
@hstk30-hw This patch is now ready for review. |
Need a test case at least. |
Done! |
@shafik Take a look, pls. |
816fe1e
to
a4236f9
Compare
a4236f9
to
4920812
Compare
Hi,@hstk30-hw, @shafik, @AaronBallman just wanted to check if there’s anything further needed from my side for this patch. I’d be happy to help clarify or adjust anything. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ugh, sorry for the delayed review! I had a comment several days ago but forgot to hit Submit. :-/
clang/lib/AST/ASTContext.cpp
Outdated
SourceManager &SM) { | ||
std::string Error; | ||
if (!NoSanitizeL->init(LangOpts.NoSanitizeFiles, Error)) { | ||
const std::string &Path = LangOpts.NoSanitizeFiles.front(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this assumes that the first file in the list is the one we cannot read; what happens if we can read that one fine but a subsequent file is where we struggle? We'd report the wrong path to the user in that case, which would be hard for them to reason about.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are two kind of error for NoSanitizeL. The first is can't open file
, the second is error parsing file
, so I think using CustomDiagID is better!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so I think using CustomDiagID is better!
Custom diagnostics are not an acceptable solution IMO; the reason is because they don't get a warning group associated with them and so users have no way to silence those diagnostics. We have some uses of the API in Clang but in every case they're the wrong tool to use.
We actually document this on the API itself, but not very clearly:
// TODO: Deprecate this once all uses are removed from Clang. |
Summary
This PR resolves #147187