xref: /llvm-project/compiler-rt/test/profile/Posix/gcov-destructor.c (revision d084bc291a21895fa2ecc74e2d1c9d1818ba4fd7)
148c196f5SFangrui Song /// Test that destructors and destructors whose priorities are greater than 100 are tracked.
2*d084bc29SJérôme Duval // XFAIL: target={{.*haiku.*}}
348c196f5SFangrui Song // RUN: mkdir -p %t.dir && cd %t.dir
4ac272287SAaron Ballman // RUN: %clang --coverage %s -o %t -dumpdir ./
548c196f5SFangrui Song // RUN: rm -f gcov-destructor.gcda && %run %t
648c196f5SFangrui Song // RUN: llvm-cov gcov -t gcov-destructor.gcda | FileCheck %s
785e14432SAmara Emerson // UNSUPPORTED: darwin
848c196f5SFangrui Song 
948c196f5SFangrui Song #include <unistd.h>
1048c196f5SFangrui Song 
1148c196f5SFangrui Song void before_exec() {}                   // CHECK:      1: [[#@LINE]]:void before_exec
1248c196f5SFangrui Song void after_exec() {}                    // CHECK-NEXT: 1: [[#@LINE]]:void after_exec
1348c196f5SFangrui Song 
1448c196f5SFangrui Song __attribute__((constructor))            // CHECK:      -: [[#@LINE]]:__attribute__
1548c196f5SFangrui Song void constructor() {}                   // CHECK-NEXT: 1: [[#@LINE]]:
1648c196f5SFangrui Song 
1748c196f5SFangrui Song /// Runs before __llvm_gcov_writeout.
1848c196f5SFangrui Song __attribute__((destructor))             // CHECK:      -: [[#@LINE]]:__attribute__
1948c196f5SFangrui Song void destructor() {}                    // CHECK-NEXT: 1: [[#@LINE]]:
2048c196f5SFangrui Song 
2148c196f5SFangrui Song __attribute__((destructor(101)))        // CHECK:      -: [[#@LINE]]:__attribute__
2248c196f5SFangrui Song void destructor_101() {}                // CHECK-NEXT: 1: [[#@LINE]]:
2348c196f5SFangrui Song 
2448c196f5SFangrui Song /// Runs after __llvm_gcov_writeout.
2548c196f5SFangrui Song __attribute__((destructor(99)))         // CHECK:      -: [[#@LINE]]:__attribute__
2648c196f5SFangrui Song void destructor_99() {}                 // CHECK-NEXT: #####: [[#@LINE]]:
2748c196f5SFangrui Song 
2848c196f5SFangrui Song int main() {
2948c196f5SFangrui Song   before_exec();
3048c196f5SFangrui Song   // Implicit writeout.
3148c196f5SFangrui Song   execl("/not_exist", "not_exist", (char *)0);
3248c196f5SFangrui Song   // Still tracked.
3348c196f5SFangrui Song   after_exec();
3448c196f5SFangrui Song   return 0;
3548c196f5SFangrui Song }
36