Reset coverage data on fork(). For memory-mapped mode (coverage_direct=1) this helps avoid loss of data (before this change two processes would write to the same file simultaneously). For normal mode, this reduces coverage dump size, because PCs from the parent process are no longer inherited by the child. llvm-svn: 210180
39 lines
949 B
C++
39 lines
949 B
C++
// RUN: %clangxx_asan -mllvm -asan-coverage=1 %s -o %t
|
|
// RUN: export ASAN_OPTIONS=coverage=1:coverage_direct=0:verbosity=1
|
|
// RUN: rm -rf %T/coverage-fork
|
|
// RUN: mkdir -p %T/coverage-fork && cd %T/coverage-fork
|
|
// RUN: %run %t 2>&1 | FileCheck %s
|
|
//
|
|
// XFAIL: android
|
|
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <unistd.h>
|
|
|
|
__attribute__((noinline))
|
|
void foo() { printf("foo\n"); }
|
|
|
|
__attribute__((noinline))
|
|
void bar() { printf("bar\n"); }
|
|
|
|
__attribute__((noinline))
|
|
void baz() { printf("baz\n"); }
|
|
|
|
int main(int argc, char **argv) {
|
|
pid_t child_pid = fork();
|
|
if (child_pid == 0) {
|
|
fprintf(stderr, "Child PID: %d\n", getpid());
|
|
baz();
|
|
} else {
|
|
fprintf(stderr, "Parent PID: %d\n", getpid());
|
|
foo();
|
|
bar();
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
// CHECK-DAG: Child PID: [[ChildPID:[0-9]+]]
|
|
// CHECK-DAG: [[ChildPID]].sancov: 1 PCs written
|
|
// CHECK-DAG: Parent PID: [[ParentPID:[0-9]+]]
|
|
// CHECK-DAG: [[ParentPID]].sancov: 3 PCs written
|