blob: 11f3a276c7c7e7e98489fc77e8ba8d912e2dcbfb [file] [log] [blame]
Erich Keane281d20b2018-01-08 21:34:17 +00001// RUN: %clang_cc1 -triple x86_64-linux-gnu -fsyntax-only -verify -fexceptions -fcxx-exceptions %s -std=c++14
George Burgess IVd74b6a82018-01-16 03:01:50 +00002void __attribute__((target("default"))) invalid_features(void);
Erich Keane29636aa2018-02-16 17:31:59 +00003//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 IVd74b6a82018-01-16 03:01:50 +00005void __attribute__((target("hello_world"))) invalid_features(void);
6//expected-error@+1 {{function multiversioning doesn't support feature 'no-sse4.2'}}
7void __attribute__((target("no-sse4.2"))) invalid_features(void);
8
Erich Keane281d20b2018-01-08 21:34:17 +00009void __attribute__((target("sse4.2"))) no_default(void);
10void __attribute__((target("arch=sandybridge"))) no_default(void);
11
12void use1(void){
13 // expected-error@+1 {{no matching function for call to 'no_default'}}
14 no_default();
15}
16constexpr int __attribute__((target("sse4.2"))) foo(void) { return 0; }
17constexpr int __attribute__((target("arch=sandybridge"))) foo(void);
18//expected-error@+1 {{multiversioned function declaration has a different constexpr specification}}
19int __attribute__((target("arch=ivybridge"))) foo(void) {return 1;}
20constexpr int __attribute__((target("default"))) foo(void) { return 2; }
21
22int __attribute__((target("sse4.2"))) foo2(void) { return 0; }
23//expected-error@+1 {{multiversioned function declaration has a different constexpr specification}}
24constexpr int __attribute__((target("arch=sandybridge"))) foo2(void);
25int __attribute__((target("arch=ivybridge"))) foo2(void) {return 1;}
26int __attribute__((target("default"))) foo2(void) { return 2; }
27
28static int __attribute__((target("sse4.2"))) bar(void) { return 0; }
29static int __attribute__((target("arch=sandybridge"))) bar(void);
30//expected-error@+1 {{multiversioned function declaration has a different storage class}}
31int __attribute__((target("arch=ivybridge"))) bar(void) {return 1;}
32static int __attribute__((target("default"))) bar(void) { return 2; }
33
34int __attribute__((target("sse4.2"))) bar2(void) { return 0; }
35//expected-error@+1 {{multiversioned function declaration has a different storage class}}
36static int __attribute__((target("arch=sandybridge"))) bar2(void);
37int __attribute__((target("arch=ivybridge"))) bar2(void) {return 1;}
38int __attribute__((target("default"))) bar2(void) { return 2; }
39
40
41inline int __attribute__((target("sse4.2"))) baz(void) { return 0; }
42inline int __attribute__((target("arch=sandybridge"))) baz(void);
43//expected-error@+1 {{multiversioned function declaration has a different inline specification}}
44int __attribute__((target("arch=ivybridge"))) baz(void) {return 1;}
45inline int __attribute__((target("default"))) baz(void) { return 2; }
46
47int __attribute__((target("sse4.2"))) baz2(void) { return 0; }
48//expected-error@+1 {{multiversioned function declaration has a different inline specification}}
49inline int __attribute__((target("arch=sandybridge"))) baz2(void);
50int __attribute__((target("arch=ivybridge"))) baz2(void) {return 1;}
51int __attribute__((target("default"))) baz2(void) { return 2; }
52
53float __attribute__((target("sse4.2"))) bock(void) { return 0; }
54//expected-error@+1 {{multiversioned function declaration has a different return type}}
55int __attribute__((target("arch=sandybridge"))) bock(void);
56//expected-error@+1 {{multiversioned function declaration has a different return type}}
57int __attribute__((target("arch=ivybridge"))) bock(void) {return 1;}
58//expected-error@+1 {{multiversioned function declaration has a different return type}}
59int __attribute__((target("default"))) bock(void) { return 2; }
60
61int __attribute__((target("sse4.2"))) bock2(void) { return 0; }
62//expected-error@+1 {{multiversioned function declaration has a different return type}}
63float __attribute__((target("arch=sandybridge"))) bock2(void);
64int __attribute__((target("arch=ivybridge"))) bock2(void) {return 1;}
65int __attribute__((target("default"))) bock2(void) { return 2; }
66
67auto __attribute__((target("sse4.2"))) bock3(void) -> int { return 0; }
68//expected-error@+1 {{multiversioned function declaration has a different return type}}
69auto __attribute__((target("arch=sandybridge"))) bock3(void) -> short { return (short)0;}
70
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}}
74int __attribute__((target("arch=sandybridge"))) bock4(void) noexcept(true) { return 1;}
75
76// FIXME: Add support for templates and virtual functions!
77template<typename T>
78int __attribute__((target("sse4.2"))) foo(T) { return 0; }
79// expected-error@+2 {{multiversioned functions do not yet support function templates}}
80template<typename T>
81int __attribute__((target("arch=sandybridge"))) foo(T);
82
83// expected-error@+2 {{multiversioned functions do not yet support function templates}}
84template<typename T>
85int __attribute__((target("default"))) foo(T) { return 2; }
86
87struct 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
102extern "C" {
103int __attribute__((target("sse4.2"))) diff_mangle(void) { return 0; }
104}
105//expected-error@+1 {{multiversioned function declaration has a different linkage}}
106int __attribute__((target("arch=sandybridge"))) diff_mangle(void) { return 0; }
107
108// expected-error@+1 {{multiversioned functions do not yet support deduced return types}}
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
112auto __attribute__((target("default"))) trailing_return(void)-> int { return 0; }
113
114__attribute__((target("default"))) void DiffDecl();
115namespace N {
116using ::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
123struct 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
135class 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")))
144int SecretAccessor(Secret &s) {
145 return s.i;
146}
147
148__attribute__((target("arch=sandybridge")))
149int SecretAccessor(Secret &s) {
150 return s.i + 2;
151}
152
153__attribute__((target("arch=ivybridge")))
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
160constexpr int __attribute__((target("sse4.2"))) constexpr_foo(void) {
161 return 0;
162}
163constexpr int __attribute__((target("arch=sandybridge"))) constexpr_foo(void);
164constexpr int __attribute__((target("arch=ivybridge"))) constexpr_foo(void) {
165 return 1;
166}
167constexpr int __attribute__((target("default"))) constexpr_foo(void) {
168 return 2;
169}
170
171void constexpr_test() {
172 static_assert(foo() == 2, "Should call 'default' in a constexpr context");
173}
174
175struct BadOutOfLine {
176 int __attribute__((target("sse4.2"))) foo(int);
177 int __attribute__((target("default"))) foo(int);
178};
179
180int __attribute__((target("sse4.2"))) BadOutOfLine::foo(int) { return 0; }
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}}
185int __attribute__((target("arch=atom"))) BadOutOfLine::foo(int) { return 1; }