Flush all output streams in flushAndExit

Also detect reading past the end of the infile for debug_determinism tracing
This commit is contained in:
Andrew Noyes 2022-03-03 13:55:43 -08:00 committed by Jingyu Zhou
parent 36edfb8820
commit a827e1cbd5
2 changed files with 7 additions and 3 deletions

View File

@ -40,11 +40,11 @@ extern "C" void __sanitizer_cov_trace_pc_guard(uint32_t* guard) {
if (!guard) {
return;
}
fwrite(guard, 1, sizeof(*guard), out);
fwrite(guard, sizeof(*guard), 1, out);
if (in) {
uint32_t theirs;
fread(&theirs, 1, sizeof(theirs), in);
if (*guard != theirs) {
auto read = fread(&theirs, sizeof(theirs), 1, in);
if (read != 1 || *guard != theirs) {
printf("Non-determinism detected\n");
loop_forever();
}

View File

@ -3231,6 +3231,10 @@ extern "C" void flushAndExit(int exitCode) {
flushTraceFileVoid();
fflush(stdout);
closeTraceFile();
// Flush all output streams. The original intent is to flush the outfile for contrib/debug_determinism.
fflush(nullptr);
#ifdef USE_GCOV
__gcov_flush();
#endif