[profile] Add -fprofile-instr-generate tests for weak definition and various linkages

This commit is contained in:
Fangrui Song 2021-06-04 10:26:55 -07:00
parent ba04c7c128
commit b19c0ac7dd
2 changed files with 31 additions and 0 deletions

View File

@ -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{{.*}}

View File

@ -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 <stdio.h>
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();
}