From adbb7b7b574bf1d1f0b3f4e26adf6786979b2da1 Mon Sep 17 00:00:00 2001 From: Xinliang David Li Date: Sun, 28 Feb 2016 00:45:13 +0000 Subject: [PATCH] [PGO] add a test for available_externally functions llvm-svn: 262161 --- .../test/profile/Inputs/extern_template.cpp | 14 +++++++++++ compiler-rt/test/profile/Inputs/extern_template.h | 17 +++++++++++++ .../test/profile/Inputs/extern_template1.cpp | 9 +++++++ .../test/profile/Inputs/extern_template2.cpp | 9 +++++++ .../test/profile/Linux/extern_template.test | 29 ++++++++++++++++++++++ 5 files changed, 78 insertions(+) create mode 100644 compiler-rt/test/profile/Inputs/extern_template.cpp create mode 100644 compiler-rt/test/profile/Inputs/extern_template.h create mode 100644 compiler-rt/test/profile/Inputs/extern_template1.cpp create mode 100644 compiler-rt/test/profile/Inputs/extern_template2.cpp create mode 100644 compiler-rt/test/profile/Linux/extern_template.test diff --git a/compiler-rt/test/profile/Inputs/extern_template.cpp b/compiler-rt/test/profile/Inputs/extern_template.cpp new file mode 100644 index 0000000..98c6c16 --- /dev/null +++ b/compiler-rt/test/profile/Inputs/extern_template.cpp @@ -0,0 +1,14 @@ +#define DEF +#include "extern_template.h" +#undef DEF +extern int bar(); +extern int foo(); +extern Test TO; +int main() { + foo(); + int R = bar(); + + if (R != 10) + return 1; + return 0; +} diff --git a/compiler-rt/test/profile/Inputs/extern_template.h b/compiler-rt/test/profile/Inputs/extern_template.h new file mode 100644 index 0000000..01c1d1a --- /dev/null +++ b/compiler-rt/test/profile/Inputs/extern_template.h @@ -0,0 +1,17 @@ +template struct Test { + Test() : M(10) {} + void doIt(int N) { // CHECK: 2| [[@LINE]]| void doIt + if (N > 10) { // CHECK: 2| [[@LINE]]| if (N > 10) { + M += 2; // CHECK: 1| [[@LINE]]| M += 2; + } else // CHECK: 1| [[@LINE]]| } else + M -= 2; // CHECK: 1| [[@LINE]]| M -= 2; + } + T M; +}; + +#ifdef USE +extern template struct Test; +#endif +#ifdef DEF +template struct Test; +#endif diff --git a/compiler-rt/test/profile/Inputs/extern_template1.cpp b/compiler-rt/test/profile/Inputs/extern_template1.cpp new file mode 100644 index 0000000..372ffd2 --- /dev/null +++ b/compiler-rt/test/profile/Inputs/extern_template1.cpp @@ -0,0 +1,9 @@ +#define USE +#include "extern_template.h" +#undef USE + +Test TO; +int foo() { + TO.doIt(20); + return TO.M; +} diff --git a/compiler-rt/test/profile/Inputs/extern_template2.cpp b/compiler-rt/test/profile/Inputs/extern_template2.cpp new file mode 100644 index 0000000..ac2f858 --- /dev/null +++ b/compiler-rt/test/profile/Inputs/extern_template2.cpp @@ -0,0 +1,9 @@ +#define USE +#include "extern_template.h" +#undef USE + +extern Test TO; +int bar() { + TO.doIt(5); + return TO.M; +} diff --git a/compiler-rt/test/profile/Linux/extern_template.test b/compiler-rt/test/profile/Linux/extern_template.test new file mode 100644 index 0000000..ada4d23 --- /dev/null +++ b/compiler-rt/test/profile/Linux/extern_template.test @@ -0,0 +1,29 @@ +// RUN: %clang -O2 -c -o %t.0.o %S/../Inputs/extern_template.cpp +// RUN: %clang_profgen -O2 -c -o %t.o %S/../Inputs/extern_template.cpp +// RUN: %clang_profgen -O2 -fcoverage-mapping %S/../Inputs/extern_template1.cpp %S/../Inputs/extern_template2.cpp %t.o -o %t +// RUN: env LLVM_PROFILE_FILE=%t.profraw %t +// RUN: llvm-profdata show --all-functions %t.profraw | FileCheck %s +// RUN: llvm-profdata merge -o %t.profdata %t.profraw +// RUN: llvm-cov show -instr-profile=%t.profdata %t | FileCheck %S/../Inputs/extern_template.h +// RUN: %clang_profgen -O2 -fcoverage-mapping %S/../Inputs/extern_template1.cpp %S/../Inputs/extern_template2.cpp %t.0.o -o %t.0 +// RUN: env LLVM_PROFILE_FILE=%t.0.profraw %t.0 +// RUN: llvm-profdata show --all-functions %t.0.profraw | FileCheck %s +// RUN: llvm-profdata merge -o %t.0.profdata %t.0.profraw +// RUN: llvm-cov show -instr-profile=%t.0.profdata %t.0 | FileCheck %S/../Inputs/extern_template.h +#define DEF +#include "extern_template.h" +#undef DEF +extern int bar(); +extern int foo(); +extern Test TO; +int main() { + foo(); + int R = bar(); + + if (R != 10) + return 1; + return 0; +} +// No duplicate entries +// CHECK: _ZN4TestIiE4doItEi: +// CHECK-NOT: _ZN4TestIiE4doItEi: -- 2.7.4