1/// Test that destructors and destructors whose priorities are greater than 100 are tracked.
2// RUN: mkdir -p %t.dir && cd %t.dir
3// RUN: %clang --coverage %s -o %t -dumpdir ./
4// RUN: rm -f gcov-destructor.gcda && %run %t
5// RUN: llvm-cov gcov -t gcov-destructor.gcda | FileCheck %s
6// UNSUPPORTED: darwin
7
8#include <unistd.h>
9
10void before_exec() {} // CHECK: 1: [[#@LINE]]:void before_exec
11void after_exec() {} // CHECK-NEXT: 1: [[#@LINE]]:void after_exec
12
13__attribute__((constructor)) // CHECK: -: [[#@LINE]]:__attribute__
14void constructor() {} // CHECK-NEXT: 1: [[#@LINE]]:
15
16/// Runs before __llvm_gcov_writeout.
17__attribute__((destructor)) // CHECK: -: [[#@LINE]]:__attribute__
18void destructor() {} // CHECK-NEXT: 1: [[#@LINE]]:
19
20__attribute__((destructor(101))) // CHECK: -: [[#@LINE]]:__attribute__
21void destructor_101() {} // CHECK-NEXT: 1: [[#@LINE]]:
22
23/// Runs after __llvm_gcov_writeout.
24__attribute__((destructor(99))) // CHECK: -: [[#@LINE]]:__attribute__
25void destructor_99() {} // CHECK-NEXT: #####: [[#@LINE]]:
26
27int main() {
28 before_exec();
29 // Implicit writeout.
30 execl(path: "/not_exist", arg: "not_exist", (char *)0);
31 // Still tracked.
32 after_exec();
33 return 0;
34}
35

source code of compiler-rt/test/profile/Posix/gcov-destructor.c