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

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 4 10:27:01 PDT 2021


Author: Fangrui Song
Date: 2021-06-04T10:26:55-07:00
New Revision: b19c0ac7dd61c6929a633f636bded7623d6e7065

URL: https://github.com/llvm/llvm-project/commit/b19c0ac7dd61c6929a633f636bded7623d6e7065
DIFF: https://github.com/llvm/llvm-project/commit/b19c0ac7dd61c6929a633f636bded7623d6e7065.diff

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

Added: 
    compiler-rt/test/profile/Linux/coverage-linkage-lld.cpp
    compiler-rt/test/profile/Linux/coverage-linkage.cpp

Modified: 
    

Removed: 
    


################################################################################
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 <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();
+}


        


More information about the llvm-commits mailing list