Erich Keane | 281d20b | 2018-01-08 21:34:17 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -triple x86_64-linux-gnu -fsyntax-only -verify -fexceptions -fcxx-exceptions %s -std=c++14 |
George Burgess IV | d74b6a8 | 2018-01-16 03:01:50 +0000 | [diff] [blame] | 2 | void __attribute__((target("default"))) invalid_features(void); |
Erich Keane | 29636aa | 2018-02-16 17:31:59 +0000 | [diff] [blame] | 3 | //expected-error@+2 {{function declaration is missing 'target' attribute in a multiversioned function}} |
| 4 | //expected-warning@+1 {{unsupported 'hello_world' in the 'target' attribute string; 'target' attribute ignored}} |
George Burgess IV | d74b6a8 | 2018-01-16 03:01:50 +0000 | [diff] [blame] | 5 | void __attribute__((target("hello_world"))) invalid_features(void); |
| 6 | //expected-error@+1 {{function multiversioning doesn't support feature 'no-sse4.2'}} |
| 7 | void __attribute__((target("no-sse4.2"))) invalid_features(void); |
| 8 | |
Erich Keane | 281d20b | 2018-01-08 21:34:17 +0000 | [diff] [blame] | 9 | void __attribute__((target("sse4.2"))) no_default(void); |
| 10 | void __attribute__((target("arch=sandybridge"))) no_default(void); |
| 11 | |
| 12 | void use1(void){ |
| 13 | // expected-error@+1 {{no matching function for call to 'no_default'}} |
| 14 | no_default(); |
| 15 | } |
| 16 | constexpr int __attribute__((target("sse4.2"))) foo(void) { return 0; } |
| 17 | constexpr int __attribute__((target("arch=sandybridge"))) foo(void); |
| 18 | //expected-error@+1 {{multiversioned function declaration has a different constexpr specification}} |
| 19 | int __attribute__((target("arch=ivybridge"))) foo(void) {return 1;} |
| 20 | constexpr int __attribute__((target("default"))) foo(void) { return 2; } |
| 21 | |
| 22 | int __attribute__((target("sse4.2"))) foo2(void) { return 0; } |
| 23 | //expected-error@+1 {{multiversioned function declaration has a different constexpr specification}} |
| 24 | constexpr int __attribute__((target("arch=sandybridge"))) foo2(void); |
| 25 | int __attribute__((target("arch=ivybridge"))) foo2(void) {return 1;} |
| 26 | int __attribute__((target("default"))) foo2(void) { return 2; } |
| 27 | |
| 28 | static int __attribute__((target("sse4.2"))) bar(void) { return 0; } |
| 29 | static int __attribute__((target("arch=sandybridge"))) bar(void); |
| 30 | //expected-error@+1 {{multiversioned function declaration has a different storage class}} |
| 31 | int __attribute__((target("arch=ivybridge"))) bar(void) {return 1;} |
| 32 | static int __attribute__((target("default"))) bar(void) { return 2; } |
| 33 | |
| 34 | int __attribute__((target("sse4.2"))) bar2(void) { return 0; } |
| 35 | //expected-error@+1 {{multiversioned function declaration has a different storage class}} |
| 36 | static int __attribute__((target("arch=sandybridge"))) bar2(void); |
| 37 | int __attribute__((target("arch=ivybridge"))) bar2(void) {return 1;} |
| 38 | int __attribute__((target("default"))) bar2(void) { return 2; } |
| 39 | |
| 40 | |
| 41 | inline int __attribute__((target("sse4.2"))) baz(void) { return 0; } |
| 42 | inline int __attribute__((target("arch=sandybridge"))) baz(void); |
| 43 | //expected-error@+1 {{multiversioned function declaration has a different inline specification}} |
| 44 | int __attribute__((target("arch=ivybridge"))) baz(void) {return 1;} |
| 45 | inline int __attribute__((target("default"))) baz(void) { return 2; } |
| 46 | |
| 47 | int __attribute__((target("sse4.2"))) baz2(void) { return 0; } |
| 48 | //expected-error@+1 {{multiversioned function declaration has a different inline specification}} |
| 49 | inline int __attribute__((target("arch=sandybridge"))) baz2(void); |
| 50 | int __attribute__((target("arch=ivybridge"))) baz2(void) {return 1;} |
| 51 | int __attribute__((target("default"))) baz2(void) { return 2; } |
| 52 | |
| 53 | float __attribute__((target("sse4.2"))) bock(void) { return 0; } |
| 54 | //expected-error@+1 {{multiversioned function declaration has a different return type}} |
| 55 | int __attribute__((target("arch=sandybridge"))) bock(void); |
| 56 | //expected-error@+1 {{multiversioned function declaration has a different return type}} |
| 57 | int __attribute__((target("arch=ivybridge"))) bock(void) {return 1;} |
| 58 | //expected-error@+1 {{multiversioned function declaration has a different return type}} |
| 59 | int __attribute__((target("default"))) bock(void) { return 2; } |
| 60 | |
| 61 | int __attribute__((target("sse4.2"))) bock2(void) { return 0; } |
| 62 | //expected-error@+1 {{multiversioned function declaration has a different return type}} |
| 63 | float __attribute__((target("arch=sandybridge"))) bock2(void); |
| 64 | int __attribute__((target("arch=ivybridge"))) bock2(void) {return 1;} |
| 65 | int __attribute__((target("default"))) bock2(void) { return 2; } |
| 66 | |
| 67 | auto __attribute__((target("sse4.2"))) bock3(void) -> int { return 0; } |
| 68 | //expected-error@+1 {{multiversioned function declaration has a different return type}} |
| 69 | auto __attribute__((target("arch=sandybridge"))) bock3(void) -> short { return (short)0;} |
| 70 | |
| 71 | int __attribute__((target("sse4.2"))) bock4(void) noexcept(false) { return 0; } |
| 72 | //expected-error@+2 {{exception specification in declaration does not match previous declaration}} |
| 73 | //expected-note@-2 {{previous declaration is here}} |
| 74 | int __attribute__((target("arch=sandybridge"))) bock4(void) noexcept(true) { return 1;} |
| 75 | |
| 76 | // FIXME: Add support for templates and virtual functions! |
| 77 | template<typename T> |
| 78 | int __attribute__((target("sse4.2"))) foo(T) { return 0; } |
| 79 | // expected-error@+2 {{multiversioned functions do not yet support function templates}} |
| 80 | template<typename T> |
| 81 | int __attribute__((target("arch=sandybridge"))) foo(T); |
| 82 | |
| 83 | // expected-error@+2 {{multiversioned functions do not yet support function templates}} |
| 84 | template<typename T> |
| 85 | int __attribute__((target("default"))) foo(T) { return 2; } |
| 86 | |
| 87 | struct S { |
| 88 | template<typename T> |
| 89 | int __attribute__((target("sse4.2"))) foo(T) { return 0; } |
| 90 | // expected-error@+2 {{multiversioned functions do not yet support function templates}} |
| 91 | template<typename T> |
| 92 | int __attribute__((target("arch=sandybridge"))) foo(T); |
| 93 | |
| 94 | // expected-error@+2 {{multiversioned functions do not yet support function templates}} |
| 95 | template<typename T> |
| 96 | int __attribute__((target("default"))) foo(T) { return 2; } |
| 97 | |
| 98 | // expected-error@+1 {{multiversioned functions do not yet support virtual functions}} |
| 99 | virtual void __attribute__((target("default"))) virt(); |
| 100 | }; |
| 101 | |
| 102 | extern "C" { |
| 103 | int __attribute__((target("sse4.2"))) diff_mangle(void) { return 0; } |
| 104 | } |
| 105 | //expected-error@+1 {{multiversioned function declaration has a different linkage}} |
| 106 | int __attribute__((target("arch=sandybridge"))) diff_mangle(void) { return 0; } |
| 107 | |
| 108 | // expected-error@+1 {{multiversioned functions do not yet support deduced return types}} |
| 109 | auto __attribute__((target("default"))) deduced_return(void) { return 0; } |
| 110 | // expected-error@-1 {{cannot initialize return object of type 'auto' with an rvalue of type 'int'}} |
| 111 | |
| 112 | auto __attribute__((target("default"))) trailing_return(void)-> int { return 0; } |
| 113 | |
| 114 | __attribute__((target("default"))) void DiffDecl(); |
| 115 | namespace N { |
| 116 | using ::DiffDecl; |
| 117 | // expected-error@+3 {{declaration conflicts with target of using declaration already in scope}} |
| 118 | // expected-note@-4 {{target of using declaration}} |
| 119 | // expected-note@-3 {{using declaration}} |
| 120 | __attribute__((target("arch=sandybridge"))) void DiffDecl(); |
| 121 | } // namespace N |
| 122 | |
| 123 | struct SpecialFuncs { |
| 124 | // expected-error@+1 {{multiversioned functions do not yet support constructors}} |
| 125 | __attribute__((target("default"))) SpecialFuncs(); |
| 126 | // expected-error@+1 {{multiversioned functions do not yet support destructors}} |
| 127 | __attribute__((target("default"))) ~SpecialFuncs(); |
| 128 | |
| 129 | // expected-error@+1 {{multiversioned functions do not yet support defaulted functions}} |
| 130 | SpecialFuncs& __attribute__((target("default"))) operator=(const SpecialFuncs&) = default; |
| 131 | // expected-error@+1 {{multiversioned functions do not yet support deleted functions}} |
| 132 | SpecialFuncs& __attribute__((target("default"))) operator=(SpecialFuncs&&) = delete; |
| 133 | }; |
| 134 | |
| 135 | class Secret { |
| 136 | int i = 0; |
| 137 | __attribute__((target("default"))) |
| 138 | friend int SecretAccessor(Secret &s); |
| 139 | __attribute__((target("arch=sandybridge"))) |
| 140 | friend int SecretAccessor(Secret &s); |
| 141 | }; |
| 142 | |
| 143 | __attribute__((target("default"))) |
| 144 | int SecretAccessor(Secret &s) { |
| 145 | return s.i; |
| 146 | } |
| 147 | |
| 148 | __attribute__((target("arch=sandybridge"))) |
| 149 | int SecretAccessor(Secret &s) { |
| 150 | return s.i + 2; |
| 151 | } |
| 152 | |
| 153 | __attribute__((target("arch=ivybridge"))) |
| 154 | int SecretAccessor(Secret &s) { |
| 155 | //expected-error@+2{{'i' is a private member of 'Secret'}} |
| 156 | //expected-note@-20{{implicitly declared private here}} |
| 157 | return s.i + 3; |
| 158 | } |
| 159 | |
| 160 | constexpr int __attribute__((target("sse4.2"))) constexpr_foo(void) { |
| 161 | return 0; |
| 162 | } |
| 163 | constexpr int __attribute__((target("arch=sandybridge"))) constexpr_foo(void); |
| 164 | constexpr int __attribute__((target("arch=ivybridge"))) constexpr_foo(void) { |
| 165 | return 1; |
| 166 | } |
| 167 | constexpr int __attribute__((target("default"))) constexpr_foo(void) { |
| 168 | return 2; |
| 169 | } |
| 170 | |
| 171 | void constexpr_test() { |
| 172 | static_assert(foo() == 2, "Should call 'default' in a constexpr context"); |
| 173 | } |
| 174 | |
| 175 | struct BadOutOfLine { |
| 176 | int __attribute__((target("sse4.2"))) foo(int); |
| 177 | int __attribute__((target("default"))) foo(int); |
| 178 | }; |
| 179 | |
| 180 | int __attribute__((target("sse4.2"))) BadOutOfLine::foo(int) { return 0; } |
| 181 | int __attribute__((target("default"))) BadOutOfLine::foo(int) { return 1; } |
| 182 | // expected-error@+3 {{out-of-line definition of 'foo' does not match any declaration in 'BadOutOfLine'}} |
| 183 | // expected-note@-3 {{member declaration nearly matches}} |
| 184 | // expected-note@-3 {{member declaration nearly matches}} |
| 185 | int __attribute__((target("arch=atom"))) BadOutOfLine::foo(int) { return 1; } |