diff --git a/compiler-rt/test/profile/Linux/coverage-linkage-lld.cpp b/compiler-rt/test/profile/Linux/coverage-linkage-lld.cpp new file mode 100644 index 000000000000..549633867c75 --- /dev/null +++ b/compiler-rt/test/profile/Linux/coverage-linkage-lld.cpp @@ -0,0 +1,8 @@ +// REQUIRES: lld-available +/// With lld --gc-sections we can ensure discarded[01] and their profc/profd +/// variables are discarded. + +// RUN: %clang_profgen -fcoverage-mapping -ffunction-sections -fuse-ld=lld -Wl,--gc-sections %S/coverage-linkage.cpp -o %t +// RUN: llvm-nm %t | FileCheck %s + +// CHECK-NOT: discarded{{.*}} diff --git a/compiler-rt/test/profile/Linux/coverage-linkage.cpp b/compiler-rt/test/profile/Linux/coverage-linkage.cpp new file mode 100644 index 000000000000..32a63fb00095 --- /dev/null +++ b/compiler-rt/test/profile/Linux/coverage-linkage.cpp @@ -0,0 +1,23 @@ +/// Test instrumentation can handle various linkages. +// RUN: %clang_profgen -fcoverage-mapping %s -o %t +// RUN: env LLVM_PROFILE_FILE=%t.profraw %run %t + +// RUN: %clang_profgen -fcoverage-mapping -ffunction-sections -Wl,--gc-sections %s -o %t +// RUN: env LLVM_PROFILE_FILE=%t.profraw %run %t + +#include + +void discarded0() {} +__attribute__((weak)) void discarded1() {} + +void external() { puts("external"); } +__attribute__((weak)) void weak() { puts("weak"); } +static void internal() { puts("internal"); } +__attribute__((noinline)) inline void linkonce_odr() { puts("linkonce_odr"); } + +int main() { + internal(); + external(); + weak(); + linkonce_odr(); +}