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 // expected-error@-1 {{cannot initialize return object of type 'auto' with an rvalue of type 'int'}} 111 trailing_return(void)112auto __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"))) SecretAccessor(Secret & s)144int SecretAccessor(Secret &s) { 145 return s.i; 146 } 147 148 __attribute__((target("arch=sandybridge"))) SecretAccessor(Secret & s)149int SecretAccessor(Secret &s) { 150 return s.i + 2; 151 } 152 153 __attribute__((target("arch=ivybridge"))) SecretAccessor(Secret & s)154int 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 constexpr_foo(void)160constexpr int __attribute__((target("sse4.2"))) constexpr_foo(void) { 161 return 0; 162 } 163 constexpr int __attribute__((target("arch=sandybridge"))) constexpr_foo(void); constexpr_foo(void)164constexpr int __attribute__((target("arch=ivybridge"))) constexpr_foo(void) { 165 return 1; 166 } constexpr_foo(void)167constexpr int __attribute__((target("default"))) constexpr_foo(void) { 168 return 2; 169 } 170 constexpr_test()171void 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 foo(int)180int __attribute__((target("sse4.2"))) BadOutOfLine::foo(int) { return 0; } foo(int)181int __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}} foo(int)185int __attribute__((target("arch=atom"))) BadOutOfLine::foo(int) { return 1; } 186