diff --git a/stdlib/public/Concurrency/Error.cpp b/stdlib/public/Concurrency/Error.cpp index 083e75cd562..f9b9c56f489 100644 --- a/stdlib/public/Concurrency/Error.cpp +++ b/stdlib/public/Concurrency/Error.cpp @@ -10,6 +10,7 @@ // //===----------------------------------------------------------------------===// +#include "swift/Runtime/Portability.h" #include "swift/Threading/Errors.h" #include #include @@ -32,10 +33,8 @@ SWIFT_VFORMAT(2) void swift::swift_Concurrency_fatalErrorv(uint32_t flags, const char *format, va_list val) { #if !SWIFT_CONCURRENCY_EMBEDDED - // TODO: copy swift_vasprintf() so we can capture the formatted log message - const char *log = format; - - vfprintf(stderr, format, val); + char *log = nullptr; + swift_vasprintf(&log, format, val); if (&_swift_willAbort != nullptr) { auto handler = _swift_willAbort.exchange(nullptr, std::memory_order_acq_rel); @@ -43,6 +42,8 @@ void swift::swift_Concurrency_fatalErrorv(uint32_t flags, const char *format, (* handler)(flags, log, nullptr); } } + + fputs(log, stderr); #else vprintf(format, val); #endif diff --git a/stdlib/public/runtime/Errors.cpp b/stdlib/public/runtime/Errors.cpp index da4f48b0c5e..05ce31801fa 100644 --- a/stdlib/public/runtime/Errors.cpp +++ b/stdlib/public/runtime/Errors.cpp @@ -420,11 +420,8 @@ void swift::swift_reportError(uint32_t flags, // Report a fatal error to system console, stderr, and crash logs, then abort. SWIFT_NORETURN void swift::fatalErrorv(uint32_t flags, const char *format, va_list args) { - char *log; -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wuninitialized" + char *log = nullptr; swift_vasprintf(&log, format, args); -#pragma GCC diagnostic pop swift_reportError(flags, log);