[clang] e463b69 - [Support] Change fatal_error_handler_t to take a const char* instead of std::string
Simon Pilgrim via cfe-commits
cfe-commits at lists.llvm.org
Tue Oct 5 02:55:49 PDT 2021
Author: Simon Pilgrim
Date: 2021-10-05T10:55:40+01:00
New Revision: e463b69736da8b0a950ecd937cf990401bdfcdeb
URL: https://github.com/llvm/llvm-project/commit/e463b69736da8b0a950ecd937cf990401bdfcdeb
DIFF: https://github.com/llvm/llvm-project/commit/e463b69736da8b0a950ecd937cf990401bdfcdeb.diff
LOG: [Support] Change fatal_error_handler_t to take a const char* instead of std::string
https://commondatastorage.googleapis.com/chromium-browser-clang/llvm-include-analysis.html
Excessive use of the <string> header has a massive impact on compile time; its most commonly included via the ErrorHandling.h header, which has to be included in many key headers, impacting many source files that have no need for std::string.
As an initial step toward removing the <string> include from ErrorHandling.h, this patch proposes to update the fatal_error_handler_t handler to just take a raw const char* instead.
The next step will be to remove the report_fatal_error std::string variant, which will involve a lot of cleanup and better use of Twine/StringRef.
Differential Revision: https://reviews.llvm.org/D111049
Added:
Modified:
clang/tools/clang-repl/ClangRepl.cpp
clang/tools/driver/cc1_main.cpp
clang/tools/driver/cc1as_main.cpp
clang/tools/libclang/FatalErrorHandler.cpp
llvm/include/llvm/Support/ErrorHandling.h
llvm/lib/Support/ErrorHandling.cpp
llvm/tools/llvm-as-fuzzer/llvm-as-fuzzer.cpp
llvm/tools/llvm-isel-fuzzer/llvm-isel-fuzzer.cpp
llvm/tools/llvm-opt-fuzzer/llvm-opt-fuzzer.cpp
Removed:
################################################################################
diff --git a/clang/tools/clang-repl/ClangRepl.cpp b/clang/tools/clang-repl/ClangRepl.cpp
index ba6bb11abc867..8e50418f705c2 100644
--- a/clang/tools/clang-repl/ClangRepl.cpp
+++ b/clang/tools/clang-repl/ClangRepl.cpp
@@ -32,7 +32,7 @@ static llvm::cl::list<std::string> OptInputs(llvm::cl::Positional,
llvm::cl::ZeroOrMore,
llvm::cl::desc("[code to run]"));
-static void LLVMErrorHandler(void *UserData, const std::string &Message,
+static void LLVMErrorHandler(void *UserData, const char *Message,
bool GenCrashDiag) {
auto &Diags = *static_cast<clang::DiagnosticsEngine *>(UserData);
diff --git a/clang/tools/driver/cc1_main.cpp b/clang/tools/driver/cc1_main.cpp
index 396d6ff529f31..13fb80fbad300 100644
--- a/clang/tools/driver/cc1_main.cpp
+++ b/clang/tools/driver/cc1_main.cpp
@@ -57,7 +57,7 @@ using namespace llvm::opt;
// Main driver
//===----------------------------------------------------------------------===//
-static void LLVMErrorHandler(void *UserData, const std::string &Message,
+static void LLVMErrorHandler(void *UserData, const char *Message,
bool GenCrashDiag) {
DiagnosticsEngine &Diags = *static_cast<DiagnosticsEngine*>(UserData);
diff --git a/clang/tools/driver/cc1as_main.cpp b/clang/tools/driver/cc1as_main.cpp
index 6549b132f6166..6816fd20e43ec 100644
--- a/clang/tools/driver/cc1as_main.cpp
+++ b/clang/tools/driver/cc1as_main.cpp
@@ -550,7 +550,7 @@ static bool ExecuteAssembler(AssemblerInvocation &Opts,
return Failed;
}
-static void LLVMErrorHandler(void *UserData, const std::string &Message,
+static void LLVMErrorHandler(void *UserData, const char *Message,
bool GenCrashDiag) {
DiagnosticsEngine &Diags = *static_cast<DiagnosticsEngine*>(UserData);
diff --git a/clang/tools/libclang/FatalErrorHandler.cpp b/clang/tools/libclang/FatalErrorHandler.cpp
index ef21569637f03..73864754c0655 100644
--- a/clang/tools/libclang/FatalErrorHandler.cpp
+++ b/clang/tools/libclang/FatalErrorHandler.cpp
@@ -11,11 +11,11 @@
#include "llvm/Support/ErrorHandling.h"
#include <stdlib.h>
-static void aborting_fatal_error_handler(void *, const std::string &reason,
+static void aborting_fatal_error_handler(void *, const char *reason,
bool) {
// Write the result out to stderr avoiding errs() because raw_ostreams can
// call report_fatal_error.
- fprintf(stderr, "LIBCLANG FATAL ERROR: %s\n", reason.c_str());
+ fprintf(stderr, "LIBCLANG FATAL ERROR: %s\n", reason);
::abort();
}
diff --git a/llvm/include/llvm/Support/ErrorHandling.h b/llvm/include/llvm/Support/ErrorHandling.h
index 81cac477cb69b..260c76fadc95a 100644
--- a/llvm/include/llvm/Support/ErrorHandling.h
+++ b/llvm/include/llvm/Support/ErrorHandling.h
@@ -18,12 +18,12 @@
#include <string>
namespace llvm {
-class StringRef;
+ class StringRef;
class Twine;
/// An error handler callback.
typedef void (*fatal_error_handler_t)(void *user_data,
- const std::string& reason,
+ const char *reason,
bool gen_crash_diag);
/// install_fatal_error_handler - Installs a new error handler to be used
diff --git a/llvm/lib/Support/ErrorHandling.cpp b/llvm/lib/Support/ErrorHandling.cpp
index ce6344284f066..b15c36f5b9e57 100644
--- a/llvm/lib/Support/ErrorHandling.cpp
+++ b/llvm/lib/Support/ErrorHandling.cpp
@@ -105,7 +105,7 @@ void llvm::report_fatal_error(const Twine &Reason, bool GenCrashDiag) {
}
if (handler) {
- handler(handlerData, Reason.str(), GenCrashDiag);
+ handler(handlerData, Reason.str().c_str(), GenCrashDiag);
} else {
// Blast the result out to stderr. We don't try hard to make sure this
// succeeds (e.g. handling EINTR) and we can't use errs() here because
@@ -218,11 +218,11 @@ void llvm::llvm_unreachable_internal(const char *msg, const char *file,
#endif
}
-static void bindingsErrorHandler(void *user_data, const std::string& reason,
+static void bindingsErrorHandler(void *user_data, const char *reason,
bool gen_crash_diag) {
LLVMFatalErrorHandler handler =
LLVM_EXTENSION reinterpret_cast<LLVMFatalErrorHandler>(user_data);
- handler(reason.c_str());
+ handler(reason);
}
void LLVMInstallFatalErrorHandler(LLVMFatalErrorHandler Handler) {
diff --git a/llvm/tools/llvm-as-fuzzer/llvm-as-fuzzer.cpp b/llvm/tools/llvm-as-fuzzer/llvm-as-fuzzer.cpp
index ec3ccbd17363d..119bf6f8d92d8 100644
--- a/llvm/tools/llvm-as-fuzzer/llvm-as-fuzzer.cpp
+++ b/llvm/tools/llvm-as-fuzzer/llvm-as-fuzzer.cpp
@@ -30,7 +30,7 @@ static jmp_buf JmpBuf;
namespace {
-void MyFatalErrorHandler(void *user_data, const std::string& reason,
+void MyFatalErrorHandler(void *user_data, const char *reason,
bool gen_crash_diag) {
// Don't bother printing reason, just return to the test function,
// since a fatal error represents a successful parse (i.e. it correctly
diff --git a/llvm/tools/llvm-isel-fuzzer/llvm-isel-fuzzer.cpp b/llvm/tools/llvm-isel-fuzzer/llvm-isel-fuzzer.cpp
index 1d93299b9e81e..f8300955964e4 100644
--- a/llvm/tools/llvm-isel-fuzzer/llvm-isel-fuzzer.cpp
+++ b/llvm/tools/llvm-isel-fuzzer/llvm-isel-fuzzer.cpp
@@ -107,7 +107,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
return 0;
}
-static void handleLLVMFatalError(void *, const std::string &Message, bool) {
+static void handleLLVMFatalError(void *, const char *Message, bool) {
// TODO: Would it be better to call into the fuzzer internals directly?
dbgs() << "LLVM ERROR: " << Message << "\n"
<< "Aborting to trigger fuzzer exit handling.\n";
diff --git a/llvm/tools/llvm-opt-fuzzer/llvm-opt-fuzzer.cpp b/llvm/tools/llvm-opt-fuzzer/llvm-opt-fuzzer.cpp
index d737f63dfd367..7abb5d7b78d90 100644
--- a/llvm/tools/llvm-opt-fuzzer/llvm-opt-fuzzer.cpp
+++ b/llvm/tools/llvm-opt-fuzzer/llvm-opt-fuzzer.cpp
@@ -170,7 +170,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
return 0;
}
-static void handleLLVMFatalError(void *, const std::string &Message, bool) {
+static void handleLLVMFatalError(void *, const char *Message, bool) {
// TODO: Would it be better to call into the fuzzer internals directly?
dbgs() << "LLVM ERROR: " << Message << "\n"
<< "Aborting to trigger fuzzer exit handling.\n";
More information about the cfe-commits
mailing list