Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / fuzzer / SanCovDump.cpp
blobc1b21a22568d69b1f4d157618edfe3973e79ce55
1 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
2 // See https://llvm.org/LICENSE.txt for license information.
3 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5 // Link this tiny library to a binary compiled with
6 // -fsanitize-coverage=inline-8bit-counters.
7 // When passed SANCOV_OUT=OUTPUT_PATH, the process will
8 // dump the 8-bit coverage counters to the file, assuming
9 // the regular exit() is called.
11 // See OutOfProcessFuzzTarget.cpp for usage.
12 #include <stdio.h>
13 #include <stdlib.h>
15 static char *CovStart, *CovEnd;
17 static void DumpCoverage() {
18 if (const char *DumpPath = getenv("SANCOV_OUT")) {
19 fprintf(stderr, "SanCovDump: %p %p %s\n", CovStart, CovEnd, DumpPath);
20 if (FILE *f = fopen(DumpPath, "w")) {
21 fwrite(CovStart, 1, CovEnd - CovStart, f);
22 fclose(f);
27 extern "C" void __sanitizer_cov_8bit_counters_init(char *Start, char *End) {
28 CovStart = Start;
29 CovEnd = End;
30 atexit(DumpCoverage);