From b19c0ac7dd61c6929a633f636bded7623d6e7065 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Fri, 4 Jun 2021 10:26:55 -0700 Subject: [PATCH] [profile] Add -fprofile-instr-generate tests for weak definition and various linkages --- .../test/profile/Linux/coverage-linkage-lld.cpp | 8 ++++++++ .../test/profile/Linux/coverage-linkage.cpp | 23 ++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 compiler-rt/test/profile/Linux/coverage-linkage-lld.cpp create mode 100644 compiler-rt/test/profile/Linux/coverage-linkage.cpp 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 0000000..5496338 --- /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 0000000..32a63fb --- /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(); +} -- 2.7.4