1 // RUN: %clang_cc1 -triple x86_64-linux-gnu -fsyntax-only -verify -fexceptions -fcxx-exceptions %s -std=c++14 2 void __attribute__((target("default"))) invalid_features(void); 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}} 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 9 void __attribute__((target("sse4.2"))) no_default(void); 10 void __attribute__((target("arch=sandybridge"))) no_default(void); 11 use1(void)12void use1(void){ 13 // expected-error@+1 {{no matching function for call to 'no_default'}} 14 no_default(); 15 } foo(void)16constexpr 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}} foo(void)19int __attribute__((target("arch=ivybridge"))) foo(void) {return 1;} foo(void)20constexpr int __attribute__((target("default"))) foo(void) { return 2; } 21 foo2(void)22int __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); foo2(void)25int __attribute__((target("arch=ivybridge"))) foo2(void) {return 1;} foo2(void)26int __attribute__((target("default"))) foo2(void) { return 2; } 27 bar(void)28static 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}} bar(void)31int __attribute__((target("arch=ivybridge"))) bar(void) {return 1;} bar(void)32static int __attribute__((target("default"))) bar(void) { return 2; } 33 bar2(void)34int __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); bar2(void)37int __attribute__((target("arch=ivybridge"))) bar2(void) {return 1;} bar2(void)38int __attribute__((target("default"))) bar2(void) { return 2; } 39 40 baz(void)41inline 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}} baz(void)44int __attribute__((target("arch=ivybridge"))) baz(void) {return 1;} baz(void)45inline int __attribute__((target("default"))) baz(void) { return 2; } 46 baz2(void)47int __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); baz2(void)50int __attribute__((target("arch=ivybridge"))) baz2(void) {return 1;} baz2(void)51int __attribute__((target("default"))) baz2(void) { return 2; } 52 bock(void)53float __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}} bock(void)57int __attribute__((target("arch=ivybridge"))) bock(void) {return 1;} 58 //expected-error@+1 {{multiversioned function declaration has a different return type}} bock(void)59int __attribute__((target("default"))) bock(void) { return 2; } 60 bock2(void)61int __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); bock2(void)64int __attribute__((target("arch=ivybridge"))) bock2(void) {return 1;} bock2(void)65int __attribute__((target("default"))) bock2(void) { return 2; } 66 bock3(void)67auto __attribute__((target("sse4.2"))) bock3(void) -> int { return 0; } 68 //expected-error@+1 {{multiversioned function declaration has a different return type}} bock3(void)69auto __attribute__((target("arch=sandybridge"))) bock3(void) -> short { return (short)0;} 70 bock4(void)71int __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}} bock4(void)74int __attribute__((target("arch=sandybridge"))) bock4(void) noexcept(true) { return 1;} 75 76 // FIXME: Add support for templates and virtual functions! 77 template<typename T> foo(T)78int __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> foo(T)85int __attribute__((target("default"))) foo(T) { return 2; } 86 87 struct S { 88 template<typename T> fooS89 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> fooS96 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" { diff_mangle(void)103int __attribute__((target("sse4.2"))) diff_mangle(void) { return 0; } 104 } 105 //expected-error@+1 {{multiversioned function declaration has a different linkage}} diff_mangle(void)106int __attribute__((target("arch=sandybridge"))) diff_mangle(void) { return 0; } 107 108 // expected-error@+1 {{multiversioned functions do not yet support deduced return types}} deduced_return(void)109auto __attribute__((target("default"))) deduced_return(void) { return 0; } 110 trailing_return(void)111auto __attribute__((target("default"))) trailing_return(void)-> int { return 0; } 112 113 __attribute__((target("default"))) void DiffDecl(); 114 namespace N { 115 using ::DiffDecl; 116 // expected-error@+3 {{declaration conflicts with target of using declaration already in scope}} 117 // expected-note@-4 {{target of using declaration}} 118 // expected-note@-3 {{using declaration}} 119 __attribute__((target("arch=sandybridge"))) void DiffDecl(); 120 } // namespace N 121 122 struct SpecialFuncs { 123 // expected-error@+1 {{multiversioned functions do not yet support constructors}} 124 __attribute__((target("default"))) SpecialFuncs(); 125 // expected-error@+1 {{multiversioned functions do not yet support destructors}} 126 __attribute__((target("default"))) ~SpecialFuncs(); 127 128 // expected-error@+1 {{multiversioned functions do not yet support defaulted functions}} 129 SpecialFuncs& __attribute__((target("default"))) operator=(const SpecialFuncs&) = default; 130 // expected-error@+1 {{multiversioned functions do not yet support deleted functions}} 131 SpecialFuncs& __attribute__((target("default"))) operator=(SpecialFuncs&&) = delete; 132 }; 133 134 class Secret { 135 int i = 0; 136 __attribute__((target("default"))) 137 friend int SecretAccessor(Secret &s); 138 __attribute__((target("arch=sandybridge"))) 139 friend int SecretAccessor(Secret &s); 140 }; 141 142 __attribute__((target("default"))) SecretAccessor(Secret & s)143int SecretAccessor(Secret &s) { 144 return s.i; 145 } 146 147 __attribute__((target("arch=sandybridge"))) SecretAccessor(Secret & s)148int SecretAccessor(Secret &s) { 149 return s.i + 2; 150 } 151 152 __attribute__((target("arch=ivybridge"))) SecretAccessor(Secret & s)153int SecretAccessor(Secret &s) { 154 //expected-error@+2{{'i' is a private member of 'Secret'}} 155 //expected-note@-20{{implicitly declared private here}} 156 return s.i + 3; 157 } 158 constexpr_foo(void)159constexpr int __attribute__((target("sse4.2"))) constexpr_foo(void) { 160 return 0; 161 } 162 constexpr int __attribute__((target("arch=sandybridge"))) constexpr_foo(void); constexpr_foo(void)163constexpr int __attribute__((target("arch=ivybridge"))) constexpr_foo(void) { 164 return 1; 165 } constexpr_foo(void)166constexpr int __attribute__((target("default"))) constexpr_foo(void) { 167 return 2; 168 } 169 constexpr_test()170void constexpr_test() { 171 static_assert(foo() == 2, "Should call 'default' in a constexpr context"); 172 } 173 174 struct BadOutOfLine { 175 int __attribute__((target("sse4.2"))) foo(int); 176 int __attribute__((target("default"))) foo(int); 177 }; 178 foo(int)179int __attribute__((target("sse4.2"))) BadOutOfLine::foo(int) { return 0; } foo(int)180int __attribute__((target("default"))) BadOutOfLine::foo(int) { return 1; } 181 // expected-error@+3 {{out-of-line definition of 'foo' does not match any declaration in 'BadOutOfLine'}} 182 // expected-note@-3 {{member declaration nearly matches}} 183 // expected-note@-3 {{member declaration nearly matches}} foo(int)184int __attribute__((target("arch=atom"))) BadOutOfLine::foo(int) { return 1; } 185