3131#endif
3232
3333namespace {
34- void error (const char *fmt, ... ) {
34+ void error (const char *prefix, const char *msg, const char *file = nullptr , unsigned line = 0 ) {
3535 char buffer[1024 ];
36- va_list argp;
3736
38- va_start (argp, fmt);
39- vsnprintf (buffer, sizeof (buffer), fmt, argp);
40- va_end (argp);
37+ if (file) {
38+ snprintf (buffer, sizeof (buffer), " %s%s at %s:%u\n " , prefix, msg, file, line);
39+ } else {
40+ snprintf (buffer, sizeof (buffer), " %s%s\n " , prefix, msg);
41+ }
4142
4243#if SWIFT_STDLIB_HAS_ASL
4344 asl_log (nullptr , nullptr , ASL_LEVEL_ERR, " %s" , buffer);
@@ -57,7 +58,7 @@ using namespace llvm;
5758
5859void __swift::__runtime::llvm::report_fatal_error (const char *Reason,
5960 bool GenCrashDiag) {
60- error (" LLVM ERROR: %s \n " , Reason);
61+ error (" LLVM ERROR: " , Reason);
6162 abort ();
6263}
6364
@@ -75,7 +76,7 @@ void __swift::__runtime::llvm::report_bad_alloc_error(const char *Reason,
7576 bool GenCrashDiag) {
7677 // Don't call the normal error handler. It may allocate memory. Directly write
7778 // an OOM to stderr and abort.
78- error (" LLVM ERROR: out of memory\n " );
79+ error (" LLVM ERROR: " , " out of memory" );
7980 abort ();
8081}
8182
@@ -84,12 +85,7 @@ void __swift::__runtime::llvm::llvm_unreachable_internal(
8485 // This code intentionally doesn't call the ErrorHandler callback, because
8586 // llvm_unreachable is intended to be used to indicate "impossible"
8687 // situations, and not legitimate runtime errors.
87- if (msg)
88- error (" %s\n " , msg);
89- error (" UNREACHABLE executed" );
90- if (file)
91- error (" at %s:%u" , file, line);
92- error (" !\n " );
88+ error (" " , msg ? msg : " UNREACHABLE executed!" , file, line);
9389 abort ();
9490#ifdef LLVM_BUILTIN_UNREACHABLE
9591 // Windows systems and possibly others don't declare abort() to be noreturn,
0 commit comments