31
31
#endif
32
32
33
33
namespace {
34
- void error (const char *fmt, ... ) {
34
+ void error (const char *prefix, const char *msg, const char *file = nullptr , unsigned line = 0 ) {
35
35
char buffer[1024 ];
36
- va_list argp;
37
36
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
+ }
41
42
42
43
#if SWIFT_STDLIB_HAS_ASL
43
44
asl_log (nullptr , nullptr , ASL_LEVEL_ERR, " %s" , buffer);
@@ -57,7 +58,7 @@ using namespace llvm;
57
58
58
59
void __swift::__runtime::llvm::report_fatal_error (const char *Reason,
59
60
bool GenCrashDiag) {
60
- error (" LLVM ERROR: %s \n " , Reason);
61
+ error (" LLVM ERROR: " , Reason);
61
62
abort ();
62
63
}
63
64
@@ -75,7 +76,7 @@ void __swift::__runtime::llvm::report_bad_alloc_error(const char *Reason,
75
76
bool GenCrashDiag) {
76
77
// Don't call the normal error handler. It may allocate memory. Directly write
77
78
// an OOM to stderr and abort.
78
- error (" LLVM ERROR: out of memory\n " );
79
+ error (" LLVM ERROR: " , " out of memory" );
79
80
abort ();
80
81
}
81
82
@@ -84,12 +85,7 @@ void __swift::__runtime::llvm::llvm_unreachable_internal(
84
85
// This code intentionally doesn't call the ErrorHandler callback, because
85
86
// llvm_unreachable is intended to be used to indicate "impossible"
86
87
// 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);
93
89
abort ();
94
90
#ifdef LLVM_BUILTIN_UNREACHABLE
95
91
// Windows systems and possibly others don't declare abort() to be noreturn,
0 commit comments