blob: 0dbb0c0ede84132d8f33cdd6d60cf588ecb8858b [file] [log] [blame]
Rong Xu9837ef52016-02-04 18:39:09 +00001// RUN: %clang_cc1 -triple %itanium_abi_triple -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name classtemplate.cpp %s > %tmapping
Alex Lorenze3b04a92014-08-20 17:29:47 +00002// 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
Vedant Kumara14a1f92018-01-17 18:53:51 +00005// RUN: FileCheck -input-file %tmapping %s --check-prefix=CHECK-INIT-LIST
Alex Lorenz34ac9b52014-08-19 17:32:30 +00006
7template<class TT>
8class Test {
9public:
10 enum BaseType {
11 A, C, G, T, Invalid
12 };
13 const static int BaseCount = 4;
14 double bases[BaseCount];
15
Justin Bogner94d384e2014-11-18 00:34:46 +000016 // CHECK-CONSTRUCTOR: _ZN4TestIjEC
Justin Bogner4da909b2015-02-03 21:35:49 +000017 Test() { } // CHECK-CONSTRUCTOR: File 0, [[@LINE]]:10 -> [[@LINE]]:13 = #0
Justin Bogner94d384e2014-11-18 00:34:46 +000018
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
Justin Bogner4da909b2015-02-03 21:35:49 +000022 double get(TT position) const { // FIXME-GETTER: File 0, [[@LINE]]:33 -> [[@LINE+2]]:4 = 0
Alex Lorenz34ac9b52014-08-19 17:32:30 +000023 return bases[position];
24 }
Justin Bogner94d384e2014-11-18 00:34:46 +000025 // CHECK-SETTER: _ZN4TestIjE3set
Justin Bogner4da909b2015-02-03 21:35:49 +000026 void set(TT position, double value) { // CHECK-SETTER: File 0, [[@LINE]]:39 -> [[@LINE+2]]:4 = #0
Alex Lorenz34ac9b52014-08-19 17:32:30 +000027 bases[position] = value;
28 }
29};
30
Justin Bogner94d384e2014-11-18 00:34:46 +000031class Test2 {
32 // CHECK-CONSTRUCTOR: _ZN5Test2C
Justin Bogner4da909b2015-02-03 21:35:49 +000033 Test2() { } // CHECK-CONSTRUCTOR: File 0, [[@LINE]]:11 -> [[@LINE]]:14 = 0
Justin Bogner94d384e2014-11-18 00:34:46 +000034 // CHECK-GETTER: _ZNK5Test23get
Justin Bogner4da909b2015-02-03 21:35:49 +000035 double get(unsigned position) const { // CHECK-GETTER: File 0, [[@LINE]]:39 -> [[@LINE+2]]:4 = 0
Justin Bogner94d384e2014-11-18 00:34:46 +000036 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.
43template <class T, bool = __is_final(T)> class UninstantiatedClassWithTraits {};
44template <class T> class Test3 {
45 void unmangleable(UninstantiatedClassWithTraits<T> x) {}
46};
47
Vedant Kumara14a1f92018-01-17 18:53:51 +000048void abort() __attribute__((noreturn));
49
50namespace std {
51typedef decltype(sizeof(int)) size_t;
52
53template <typename E> struct initializer_list {
54 const E *p;
55 size_t n;
56 initializer_list(const E *p, size_t n) : p(p), n(n) {}
57};
58
59template <typename F, typename S> struct pair {
60 F f;
61 S s;
62 pair(const F &f, const S &s) : f(f), s(s) {}
63};
64
65struct string {
66 const char *str;
67 string() { abort(); }
68 string(const char *S) : str(S) {}
69 ~string() { abort(); }
70};
71
72template<typename K, typename V>
73struct map {
74 using T = pair<K, V>;
75 map(initializer_list<T> i, const string &s = string()) {}
76 ~map() { abort(); }
77};
78
79}; // namespace std
80
81// CHECK-INIT-LIST-LABEL: _Z5Test4v:
82std::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
Alex Lorenz34ac9b52014-08-19 17:32:30 +000087int 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);
Vedant Kumara14a1f92018-01-17 18:53:51 +000093 Test4();
Alex Lorenz34ac9b52014-08-19 17:32:30 +000094 return 0;
95}