[docs] Add LICENSE.txt to the root of the mono-repo
[llvm-project.git] / clang / test / SemaCXX / attr-target-mv.cpp
blob5b2f0fc825f399bd52b95e04bc5bc72271f631af
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);
9 void __attribute__((target("sse4.2"))) no_default(void);
10 void __attribute__((target("arch=sandybridge"))) no_default(void);
12 void use1(void){
13 // expected-error@+1 {{no matching function for call to 'no_default'}}
14 no_default();
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; }
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; }
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 linkage}}
31 int __attribute__((target("arch=ivybridge"))) bar(void) {return 1;}
32 static int __attribute__((target("default"))) bar(void) { return 2; }
34 int __attribute__((target("sse4.2"))) bar2(void) { return 0; }
35 //expected-error@+1 {{multiversioned function declaration has a different linkage}}
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; }
41 // no diagnostic, since this doesn't change the linkage.
42 int __attribute__((target("sse4.2"))) bar3(void) { return 0; }
43 extern int __attribute__((target("arch=sandybridge"))) bar2(void);
45 namespace {
46 int __attribute__((target("sse4.2"))) bar4(void) { return 0; }
47 static int __attribute__((target("arch=sandybridge"))) bar4(void);
50 inline int __attribute__((target("sse4.2"))) baz(void) { return 0; }
51 inline int __attribute__((target("arch=sandybridge"))) baz(void);
52 //expected-error@+1 {{multiversioned function declaration has a different inline specification}}
53 int __attribute__((target("arch=ivybridge"))) baz(void) {return 1;}
54 inline int __attribute__((target("default"))) baz(void) { return 2; }
56 int __attribute__((target("sse4.2"))) baz2(void) { return 0; }
57 //expected-error@+1 {{multiversioned function declaration has a different inline specification}}
58 inline int __attribute__((target("arch=sandybridge"))) baz2(void);
59 int __attribute__((target("arch=ivybridge"))) baz2(void) {return 1;}
60 int __attribute__((target("default"))) baz2(void) { return 2; }
62 float __attribute__((target("sse4.2"))) bock(void) { return 0; }
63 //expected-error@+1 {{multiversioned function declaration has a different return type}}
64 int __attribute__((target("arch=sandybridge"))) bock(void);
65 //expected-error@+1 {{multiversioned function declaration has a different return type}}
66 int __attribute__((target("arch=ivybridge"))) bock(void) {return 1;}
67 //expected-error@+1 {{multiversioned function declaration has a different return type}}
68 int __attribute__((target("default"))) bock(void) { return 2; }
70 int __attribute__((target("sse4.2"))) bock2(void) { return 0; }
71 //expected-error@+1 {{multiversioned function declaration has a different return type}}
72 float __attribute__((target("arch=sandybridge"))) bock2(void);
73 int __attribute__((target("arch=ivybridge"))) bock2(void) {return 1;}
74 int __attribute__((target("default"))) bock2(void) { return 2; }
76 auto __attribute__((target("sse4.2"))) bock3(void) -> int { return 0; }
77 //expected-error@+1 {{multiversioned function declaration has a different return type}}
78 auto __attribute__((target("arch=sandybridge"))) bock3(void) -> short { return (short)0;}
80 int __attribute__((target("sse4.2"))) bock4(void) noexcept(false) { return 0; }
81 //expected-error@+2 {{exception specification in declaration does not match previous declaration}}
82 //expected-note@-2 {{previous declaration is here}}
83 int __attribute__((target("arch=sandybridge"))) bock4(void) noexcept(true) { return 1;}
85 // FIXME: Add support for templates and virtual functions!
86 template<typename T>
87 int __attribute__((target("sse4.2"))) foo(T) { return 0; }
88 // expected-error@+2 {{multiversioned functions do not yet support function templates}}
89 template<typename T>
90 int __attribute__((target("arch=sandybridge"))) foo(T);
92 // expected-error@+2 {{multiversioned functions do not yet support function templates}}
93 template<typename T>
94 int __attribute__((target("default"))) foo(T) { return 2; }
96 struct S {
97 template<typename T>
98 int __attribute__((target("sse4.2"))) foo(T) { return 0; }
99 // expected-error@+2 {{multiversioned functions do not yet support function templates}}
100 template<typename T>
101 int __attribute__((target("arch=sandybridge"))) foo(T);
103 // expected-error@+2 {{multiversioned functions do not yet support function templates}}
104 template<typename T>
105 int __attribute__((target("default"))) foo(T) { return 2; }
107 // expected-error@+1 {{multiversioned functions do not yet support virtual functions}}
108 virtual void __attribute__((target("default"))) virt();
111 extern "C" {
112 int __attribute__((target("sse4.2"))) diff_mangle(void) { return 0; }
114 //expected-error@+1 {{multiversioned function declaration has a different language linkage}}
115 int __attribute__((target("arch=sandybridge"))) diff_mangle(void) { return 0; }
117 // expected-error@+1 {{multiversioned functions do not yet support deduced return types}}
118 auto __attribute__((target("default"))) deduced_return(void) { return 0; }
120 auto __attribute__((target("default"))) trailing_return(void)-> int { return 0; }
122 __attribute__((target("default"))) void DiffDecl();
123 namespace N {
124 using ::DiffDecl;
125 // expected-error@+3 {{declaration conflicts with target of using declaration already in scope}}
126 // expected-note@-4 {{target of using declaration}}
127 // expected-note@-3 {{using declaration}}
128 __attribute__((target("arch=sandybridge"))) void DiffDecl();
129 } // namespace N
131 struct SpecialFuncs {
132 // expected-error@+1 {{multiversioned functions do not yet support constructors}}
133 __attribute__((target("default"))) SpecialFuncs();
134 // expected-error@+1 {{multiversioned functions do not yet support destructors}}
135 __attribute__((target("default"))) ~SpecialFuncs();
137 // expected-error@+1 {{multiversioned functions do not yet support defaulted functions}}
138 SpecialFuncs& __attribute__((target("default"))) operator=(const SpecialFuncs&) = default;
139 // expected-error@+1 {{multiversioned functions do not yet support deleted functions}}
140 SpecialFuncs& __attribute__((target("default"))) operator=(SpecialFuncs&&) = delete;
143 class Secret {
144 int i = 0;
145 __attribute__((target("default")))
146 friend int SecretAccessor(Secret &s);
147 __attribute__((target("arch=sandybridge")))
148 friend int SecretAccessor(Secret &s);
151 __attribute__((target("default")))
152 int SecretAccessor(Secret &s) {
153 return s.i;
156 __attribute__((target("arch=sandybridge")))
157 int SecretAccessor(Secret &s) {
158 return s.i + 2;
161 __attribute__((target("arch=ivybridge")))
162 int SecretAccessor(Secret &s) {
163 //expected-error@+2{{'i' is a private member of 'Secret'}}
164 //expected-note@-20{{implicitly declared private here}}
165 return s.i + 3;
168 constexpr int __attribute__((target("sse4.2"))) constexpr_foo(void) {
169 return 0;
171 constexpr int __attribute__((target("arch=sandybridge"))) constexpr_foo(void);
172 constexpr int __attribute__((target("arch=ivybridge"))) constexpr_foo(void) {
173 return 1;
175 constexpr int __attribute__((target("default"))) constexpr_foo(void) {
176 return 2;
179 void constexpr_test() {
180 static_assert(foo() == 2, "Should call 'default' in a constexpr context");
183 struct BadOutOfLine {
184 int __attribute__((target("sse4.2"))) foo(int);
185 int __attribute__((target("default"))) foo(int);
188 int __attribute__((target("sse4.2"))) BadOutOfLine::foo(int) { return 0; }
189 int __attribute__((target("default"))) BadOutOfLine::foo(int) { return 1; }
190 // expected-error@+3 {{out-of-line definition of 'foo' does not match any declaration in 'BadOutOfLine'}}
191 // expected-note@-3 {{member declaration nearly matches}}
192 // expected-note@-3 {{member declaration nearly matches}}
193 int __attribute__((target("arch=atom"))) BadOutOfLine::foo(int) { return 1; }