Skip to content

Commit

Permalink
[Support] Change fatal_error_handler_t to take a const char* instead …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
RKSimon committed Oct 5, 2021
1 parent 0a031f5 commit e463b69
Show file tree
Hide file tree
Showing 9 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion clang/tools/clang-repl/ClangRepl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion clang/tools/driver/cc1_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion clang/tools/driver/cc1as_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions clang/tools/libclang/FatalErrorHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
4 changes: 2 additions & 2 deletions llvm/include/llvm/Support/ErrorHandling.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions llvm/lib/Support/ErrorHandling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion llvm/tools/llvm-as-fuzzer/llvm-as-fuzzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion llvm/tools/llvm-isel-fuzzer/llvm-isel-fuzzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
2 changes: 1 addition & 1 deletion llvm/tools/llvm-opt-fuzzer/llvm-opt-fuzzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down

0 comments on commit e463b69

Please sign in to comment.