From 86a46b9e5c122a4f6463390e8e9bbac8f48f4bea Mon Sep 17 00:00:00 2001 From: Jannis Harder Date: Tue, 23 Sep 2025 14:19:30 +0200 Subject: [PATCH] log: Flush stdout before printing a fatal error to stderr This hasn't been an issue when using -l to redirect or when stdout is line buffered, explaining how we didn't notice this earlier, but for `yosys ... > log` that extra flush is required to ensure all messages preceding the fatal error are flushed. --- kernel/log.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/kernel/log.cc b/kernel/log.cc index 0085980b1..af083860a 100644 --- a/kernel/log.cc +++ b/kernel/log.cc @@ -331,10 +331,12 @@ static void log_error_with_prefix(std::string_view prefix, std::string str) if (log_errfile != NULL) log_files.push_back(log_errfile); - if (log_error_stderr) + if (log_error_stderr) { + log_flush(); // Make sure we flush stdout before replacing it with stderr for (auto &f : log_files) if (f == stdout) f = stderr; + } log_last_error = std::move(str); log("%s%s", prefix, log_last_error);