1 // RUN: %clang_cc1 -mllvm -emptyline-comment-coverage=false -triple %itanium_abi_triple -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name classtemplate.cpp %s > %tmapping
2 // RUN: FileCheck -input-file %tmapping %s --check-prefix=CHECK-CONSTRUCTOR
3 // RUN: FileCheck -input-file %tmapping %s --check-prefix=CHECK-GETTER
4 // RUN: FileCheck -input-file %tmapping %s --check-prefix=CHECK-SETTER
5 // RUN: FileCheck -input-file %tmapping %s --check-prefix=CHECK-INIT-LIST
6
7 template<class TT>
8 class Test {
9 public:
10 enum BaseType {
11 A, C, G, T, Invalid
12 };
13 const static int BaseCount = 4;
14 double bases[BaseCount];
15
16 // CHECK-CONSTRUCTOR: _ZN4TestIjEC
Test()17 Test() { } // CHECK-CONSTRUCTOR: File 0, [[@LINE]]:10 -> [[@LINE]]:13 = #0
18
19 // FIXME: It would be nice to emit no-coverage for get, but trying to do this
20 // runs afoul of cases like Test3::unmangleable below.
21 // FIXME-GETTER: _ZNK4TestIjE3get
get(TT position) const22 double get(TT position) const { // FIXME-GETTER: File 0, [[@LINE]]:33 -> [[@LINE+2]]:4 = 0
23 return bases[position];
24 }
25 // CHECK-SETTER: _ZN4TestIjE3set
set(TT position,double value)26 void set(TT position, double value) { // CHECK-SETTER: File 0, [[@LINE]]:39 -> [[@LINE+2]]:4 = #0
27 bases[position] = value;
28 }
29 };
30
31 class Test2 {
32 // CHECK-CONSTRUCTOR: _ZN5Test2C
Test2()33 Test2() { } // CHECK-CONSTRUCTOR: File 0, [[@LINE]]:11 -> [[@LINE]]:14 = 0
34 // CHECK-GETTER: _ZNK5Test23get
get(unsigned position) const35 double get(unsigned position) const { // CHECK-GETTER: File 0, [[@LINE]]:39 -> [[@LINE+2]]:4 = 0
36 return 0.0;
37 }
38 };
39
40 // Test3::unmangleable can't be mangled, since there isn't a complete type for
41 // the __is_final type trait expression. This would cause errors if we try to
42 // emit a no-coverage mapping for the method.
43 template <class T, bool = __is_final(T)> class UninstantiatedClassWithTraits {};
44 template <class T> class Test3 {
unmangleable(UninstantiatedClassWithTraits<T> x)45 void unmangleable(UninstantiatedClassWithTraits<T> x) {}
46 };
47
48 void abort() __attribute__((noreturn));
49
50 namespace std {
51 typedef decltype(sizeof(int)) size_t;
52
53 template <typename E> struct initializer_list {
54 const E *p;
55 size_t n;
initializer_liststd::initializer_list56 initializer_list(const E *p, size_t n) : p(p), n(n) {}
57 };
58
59 template <typename F, typename S> struct pair {
60 F f;
61 S s;
pairstd::pair62 pair(const F &f, const S &s) : f(f), s(s) {}
63 };
64
65 struct string {
66 const char *str;
stringstd::string67 string() { abort(); }
stringstd::string68 string(const char *S) : str(S) {}
~stringstd::string69 ~string() { abort(); }
70 };
71
72 template<typename K, typename V>
73 struct map {
74 using T = pair<K, V>;
mapstd::map75 map(initializer_list<T> i, const string &s = string()) {}
~mapstd::map76 ~map() { abort(); }
77 };
78
79 }; // namespace std
80
81 // CHECK-INIT-LIST-LABEL: _Z5Test4v:
Test4()82 std::map<int, int> Test4() { // CHECK-INIT-LIST: File 0, [[@LINE]]:28 -> [[@LINE+3]]:2 = #0
83 abort();
84 return std::map<int, int>{{0, 0}}; // CHECK-INIT-LIST-NEXT: [[@LINE]]:3 -> [[@LINE]]:36 = 0
85 }
86
main()87 int main() {
88 Test<unsigned> t;
89 t.set(Test<unsigned>::A, 5.5);
90 t.set(Test<unsigned>::T, 5.6);
91 t.set(Test<unsigned>::G, 5.7);
92 t.set(Test<unsigned>::C, 5.8);
93 Test4();
94 return 0;
95 }
96