Skip to content

Commit e463b69

Browse files
committed
[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
1 parent 0a031f5 commit e463b69

File tree

9 files changed

+13
-13
lines changed

9 files changed

+13
-13
lines changed

clang/tools/clang-repl/ClangRepl.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ static llvm::cl::list<std::string> OptInputs(llvm::cl::Positional,
3232
llvm::cl::ZeroOrMore,
3333
llvm::cl::desc("[code to run]"));
3434

35-
static void LLVMErrorHandler(void *UserData, const std::string &Message,
35+
static void LLVMErrorHandler(void *UserData, const char *Message,
3636
bool GenCrashDiag) {
3737
auto &Diags = *static_cast<clang::DiagnosticsEngine *>(UserData);
3838

clang/tools/driver/cc1_main.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ using namespace llvm::opt;
5757
// Main driver
5858
//===----------------------------------------------------------------------===//
5959

60-
static void LLVMErrorHandler(void *UserData, const std::string &Message,
60+
static void LLVMErrorHandler(void *UserData, const char *Message,
6161
bool GenCrashDiag) {
6262
DiagnosticsEngine &Diags = *static_cast<DiagnosticsEngine*>(UserData);
6363

clang/tools/driver/cc1as_main.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ static bool ExecuteAssembler(AssemblerInvocation &Opts,
550550
return Failed;
551551
}
552552

553-
static void LLVMErrorHandler(void *UserData, const std::string &Message,
553+
static void LLVMErrorHandler(void *UserData, const char *Message,
554554
bool GenCrashDiag) {
555555
DiagnosticsEngine &Diags = *static_cast<DiagnosticsEngine*>(UserData);
556556

clang/tools/libclang/FatalErrorHandler.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
#include "llvm/Support/ErrorHandling.h"
1212
#include <stdlib.h>
1313

14-
static void aborting_fatal_error_handler(void *, const std::string &reason,
14+
static void aborting_fatal_error_handler(void *, const char *reason,
1515
bool) {
1616
// Write the result out to stderr avoiding errs() because raw_ostreams can
1717
// call report_fatal_error.
18-
fprintf(stderr, "LIBCLANG FATAL ERROR: %s\n", reason.c_str());
18+
fprintf(stderr, "LIBCLANG FATAL ERROR: %s\n", reason);
1919
::abort();
2020
}
2121

llvm/include/llvm/Support/ErrorHandling.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@
1818
#include <string>
1919

2020
namespace llvm {
21-
class StringRef;
21+
class StringRef;
2222
class Twine;
2323

2424
/// An error handler callback.
2525
typedef void (*fatal_error_handler_t)(void *user_data,
26-
const std::string& reason,
26+
const char *reason,
2727
bool gen_crash_diag);
2828

2929
/// install_fatal_error_handler - Installs a new error handler to be used

llvm/lib/Support/ErrorHandling.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ void llvm::report_fatal_error(const Twine &Reason, bool GenCrashDiag) {
105105
}
106106

107107
if (handler) {
108-
handler(handlerData, Reason.str(), GenCrashDiag);
108+
handler(handlerData, Reason.str().c_str(), GenCrashDiag);
109109
} else {
110110
// Blast the result out to stderr. We don't try hard to make sure this
111111
// 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,
218218
#endif
219219
}
220220

221-
static void bindingsErrorHandler(void *user_data, const std::string& reason,
221+
static void bindingsErrorHandler(void *user_data, const char *reason,
222222
bool gen_crash_diag) {
223223
LLVMFatalErrorHandler handler =
224224
LLVM_EXTENSION reinterpret_cast<LLVMFatalErrorHandler>(user_data);
225-
handler(reason.c_str());
225+
handler(reason);
226226
}
227227

228228
void LLVMInstallFatalErrorHandler(LLVMFatalErrorHandler Handler) {

llvm/tools/llvm-as-fuzzer/llvm-as-fuzzer.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ static jmp_buf JmpBuf;
3030

3131
namespace {
3232

33-
void MyFatalErrorHandler(void *user_data, const std::string& reason,
33+
void MyFatalErrorHandler(void *user_data, const char *reason,
3434
bool gen_crash_diag) {
3535
// Don't bother printing reason, just return to the test function,
3636
// since a fatal error represents a successful parse (i.e. it correctly

llvm/tools/llvm-isel-fuzzer/llvm-isel-fuzzer.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
107107
return 0;
108108
}
109109

110-
static void handleLLVMFatalError(void *, const std::string &Message, bool) {
110+
static void handleLLVMFatalError(void *, const char *Message, bool) {
111111
// TODO: Would it be better to call into the fuzzer internals directly?
112112
dbgs() << "LLVM ERROR: " << Message << "\n"
113113
<< "Aborting to trigger fuzzer exit handling.\n";

llvm/tools/llvm-opt-fuzzer/llvm-opt-fuzzer.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
170170
return 0;
171171
}
172172

173-
static void handleLLVMFatalError(void *, const std::string &Message, bool) {
173+
static void handleLLVMFatalError(void *, const char *Message, bool) {
174174
// TODO: Would it be better to call into the fuzzer internals directly?
175175
dbgs() << "LLVM ERROR: " << Message << "\n"
176176
<< "Aborting to trigger fuzzer exit handling.\n";

0 commit comments

Comments
 (0)