Rong Xu | 9837ef5 | 2016-02-04 18:39:09 +0000 | [diff] [blame] | 1 | // 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 Lorenz | e3b04a9 | 2014-08-20 17:29:47 +0000 | [diff] [blame] | 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 |
Vedant Kumar | a14a1f9 | 2018-01-17 18:53:51 +0000 | [diff] [blame] | 5 | // RUN: FileCheck -input-file %tmapping %s --check-prefix=CHECK-INIT-LIST |
Alex Lorenz | 34ac9b5 | 2014-08-19 17:32:30 +0000 | [diff] [blame] | 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 | |
Justin Bogner | 94d384e | 2014-11-18 00:34:46 +0000 | [diff] [blame] | 16 | // CHECK-CONSTRUCTOR: _ZN4TestIjEC |
Justin Bogner | 4da909b | 2015-02-03 21:35:49 +0000 | [diff] [blame] | 17 | Test() { } // CHECK-CONSTRUCTOR: File 0, [[@LINE]]:10 -> [[@LINE]]:13 = #0 |
Justin Bogner | 94d384e | 2014-11-18 00:34:46 +0000 | [diff] [blame] | 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 |
Justin Bogner | 4da909b | 2015-02-03 21:35:49 +0000 | [diff] [blame] | 22 | double get(TT position) const { // FIXME-GETTER: File 0, [[@LINE]]:33 -> [[@LINE+2]]:4 = 0 |
Alex Lorenz | 34ac9b5 | 2014-08-19 17:32:30 +0000 | [diff] [blame] | 23 | return bases[position]; |
| 24 | } |
Justin Bogner | 94d384e | 2014-11-18 00:34:46 +0000 | [diff] [blame] | 25 | // CHECK-SETTER: _ZN4TestIjE3set |
Justin Bogner | 4da909b | 2015-02-03 21:35:49 +0000 | [diff] [blame] | 26 | void set(TT position, double value) { // CHECK-SETTER: File 0, [[@LINE]]:39 -> [[@LINE+2]]:4 = #0 |
Alex Lorenz | 34ac9b5 | 2014-08-19 17:32:30 +0000 | [diff] [blame] | 27 | bases[position] = value; |
| 28 | } |
| 29 | }; |
| 30 | |
Justin Bogner | 94d384e | 2014-11-18 00:34:46 +0000 | [diff] [blame] | 31 | class Test2 { |
| 32 | // CHECK-CONSTRUCTOR: _ZN5Test2C |
Justin Bogner | 4da909b | 2015-02-03 21:35:49 +0000 | [diff] [blame] | 33 | Test2() { } // CHECK-CONSTRUCTOR: File 0, [[@LINE]]:11 -> [[@LINE]]:14 = 0 |
Justin Bogner | 94d384e | 2014-11-18 00:34:46 +0000 | [diff] [blame] | 34 | // CHECK-GETTER: _ZNK5Test23get |
Justin Bogner | 4da909b | 2015-02-03 21:35:49 +0000 | [diff] [blame] | 35 | double get(unsigned position) const { // CHECK-GETTER: File 0, [[@LINE]]:39 -> [[@LINE+2]]:4 = 0 |
Justin Bogner | 94d384e | 2014-11-18 00:34:46 +0000 | [diff] [blame] | 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 { |
| 45 | void unmangleable(UninstantiatedClassWithTraits<T> x) {} |
| 46 | }; |
| 47 | |
Vedant Kumar | a14a1f9 | 2018-01-17 18:53:51 +0000 | [diff] [blame] | 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; |
| 56 | 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; |
| 62 | pair(const F &f, const S &s) : f(f), s(s) {} |
| 63 | }; |
| 64 | |
| 65 | struct string { |
| 66 | const char *str; |
| 67 | string() { abort(); } |
| 68 | string(const char *S) : str(S) {} |
| 69 | ~string() { abort(); } |
| 70 | }; |
| 71 | |
| 72 | template<typename K, typename V> |
| 73 | struct 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: |
| 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 | |
Alex Lorenz | 34ac9b5 | 2014-08-19 17:32:30 +0000 | [diff] [blame] | 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); |
Vedant Kumar | a14a1f9 | 2018-01-17 18:53:51 +0000 | [diff] [blame] | 93 | Test4(); |
Alex Lorenz | 34ac9b5 | 2014-08-19 17:32:30 +0000 | [diff] [blame] | 94 | return 0; |
| 95 | } |