1 // RUN: %clang_cc1 -triple x86_64-linux-gnu -Wno-strict-prototypes -fsyntax-only -verify %s
3 void __attribute__((target("sse4.2"))) no_default(void);
4 void __attribute__((target("arch=sandybridge"))) no_default(void);
7 // expected-error@+1 {{no matching function for call to 'no_default'}}
11 void __attribute__((target("sse4.2"))) has_def(void);
12 void __attribute__((target("default"))) has_def(void);
15 // expected-error@+2 {{reference to overloaded function could not be resolved; did you mean to call it?}}
16 // expected-note@-4 {{possible target for call}}
20 int __attribute__((target("sse4.2"))) no_proto();
21 // expected-error@-1 {{multiversioned function must have a prototype}}
22 // expected-note@+1 {{function multiversioning caused by this declaration}}
23 int __attribute__((target("arch=sandybridge"))) no_proto();
25 // The following should all be legal, since they are just redeclarations.
26 int __attribute__((target("sse4.2"))) redecl1(void);
27 int __attribute__((target("sse4.2"))) redecl1(void) { return 1; }
28 int __attribute__((target("arch=sandybridge"))) redecl1(void) { return 2; }
30 int __attribute__((target("sse4.2"))) redecl2(void) { return 1; }
31 int __attribute__((target("sse4.2"))) redecl2(void);
32 int __attribute__((target("arch=sandybridge"))) redecl2(void) { return 2; }
34 int __attribute__((target("sse4.2"))) redecl3(void) { return 0; }
35 int __attribute__((target("arch=ivybridge"))) redecl3(void) { return 1; }
36 int __attribute__((target("arch=sandybridge"))) redecl3(void);
37 int __attribute__((target("arch=sandybridge"))) redecl3(void) { return 2; }
39 int __attribute__((target("sse4.2"))) redecl4(void) { return 1; }
40 int __attribute__((target("arch=sandybridge"))) redecl4(void) { return 2; }
41 int __attribute__((target("arch=sandybridge"))) redecl4(void);
43 int __attribute__((target("sse4.2"))) redef(void) { return 1; }
44 int __attribute__((target("arch=ivybridge"))) redef(void) { return 1; }
45 int __attribute__((target("arch=sandybridge"))) redef(void) { return 2; }
46 // expected-error@+2 {{redefinition of 'redef'}}
47 // expected-note@-2 {{previous definition is here}}
48 int __attribute__((target("arch=sandybridge"))) redef(void) { return 2; }
50 int __attribute__((target("default"))) redef2(void) { return 1;}
51 // expected-error@+2 {{redefinition of 'redef2'}}
52 // expected-note@-2 {{previous definition is here}}
53 int __attribute__((target("default"))) redef2(void) { return 1;}
55 int redef3(void) { return 1; }
56 // expected-warning@+4 {{attribute declaration must precede definition}}
57 // expected-note@-2 {{previous definition is here}}
58 // expected-error@+2 {{redefinition of 'redef3'}}
59 // expected-note@-4 {{previous definition is here}}
60 int __attribute__((target("default"))) redef3(void) { return 1; }
61 // allow this, since we don't complain about more than one redefinition
62 int __attribute__((target("sse4.2"))) redef3(void) { return 1; }
64 int __attribute__((target("sse4.2"))) mv_after_use(void) { return 1; }
66 return mv_after_use();
69 // expected-error@+1 {{function declaration cannot become a multiversioned function after first usage}}
70 int __attribute__((target("arch=sandybridge"))) mv_after_use(void) { return 2; }
72 int __attribute__((target("sse4.2,arch=sandybridge"))) mangle(void) { return 1; }
73 //expected-error@+2 {{multiversioned function redeclarations require identical target attributes}}
74 //expected-note@-2 {{previous declaration is here}}
75 int __attribute__((target("arch=sandybridge,sse4.2"))) mangle(void) { return 2; }
77 // allow this, since we want to treat the 1st one as fwd-decl of the sandybridge version.
78 int prev_no_target(void);
79 int __attribute__((target("arch=sandybridge"))) prev_no_target(void) { return 2; }
80 int __attribute__((target("arch=ivybridge"))) prev_no_target(void) { return 2; }
82 int __attribute__((target("arch=sandybridge"))) prev_no_target2(void);
83 int prev_no_target2(void);
84 // expected-error@-1 {{function declaration is missing 'target' attribute in a multiversioned function}}
85 // expected-note@+1 {{function multiversioning caused by this declaration}}
86 int __attribute__((target("arch=ivybridge"))) prev_no_target2(void);
88 void __attribute__((target("sse4.2"))) addtl_attrs(void);
89 //expected-error@+2 {{attribute 'target' multiversioning cannot be combined with attribute 'no_caller_saved_registers'}}
90 void __attribute__((no_caller_saved_registers
,target("arch=sandybridge")))
93 //expected-error@+1 {{attribute 'target' multiversioning cannot be combined with attribute 'no_caller_saved_registers'}}
94 void __attribute__((target("default"), no_caller_saved_registers
)) addtl_attrs2(void);
96 //expected-error@+2 {{attribute 'target' multiversioning cannot be combined with attribute 'no_caller_saved_registers'}}
97 //expected-note@+2 {{function multiversioning caused by this declaration}}
98 void __attribute__((no_caller_saved_registers
,target("sse4.2"))) addtl_attrs3(void);
99 void __attribute__((target("arch=sandybridge"))) addtl_attrs3(void);
101 void __attribute__((target("sse4.2"))) addtl_attrs4(void);
102 void __attribute__((target("arch=sandybridge"))) addtl_attrs4(void);
103 //expected-error@+1 {{attribute 'target' multiversioning cannot be combined}}
104 void __attribute__((no_caller_saved_registers
,target("arch=ivybridge"))) addtl_attrs4(void);
106 int __attribute__((target("sse4.2"))) diff_cc(void);
107 // expected-error@+1 {{multiversioned function declaration has a different calling convention}}
108 __vectorcall
int __attribute__((target("arch=sandybridge"))) diff_cc(void);
110 int __attribute__((target("sse4.2"))) diff_ret(void);
111 // expected-error@+1 {{multiversioned function declaration has a different return type}}
112 short __attribute__((target("arch=sandybridge"))) diff_ret(void);
114 void __attribute__((target("sse4.2"), nothrow
, used
, nonnull(1))) addtl_attrs5(int*);
115 void __attribute__((target("arch=sandybridge"))) addtl_attrs5(int*);
117 void __attribute__((target("sse4.2"))) addtl_attrs6(int*);
118 void __attribute__((target("arch=sandybridge"), nothrow
, used
, nonnull
)) addtl_attrs6(int*);
120 int __attribute__((target("sse4.2"))) bad_overload1(void);
121 int __attribute__((target("arch=sandybridge"))) bad_overload1(void);
122 // expected-error@+1 {{function declaration is missing 'target' attribute in a multiversioned function}}
123 int bad_overload1(int);
125 int bad_overload2(int);
126 // expected-error@+2 {{conflicting types for 'bad_overload2'}}
127 // expected-note@-2 {{previous declaration is here}}
128 int __attribute__((target("sse4.2"))) bad_overload2(void);
129 // expected-error@+2 {{conflicting types for 'bad_overload2'}}
130 // expected-note@-5 {{previous declaration is here}}
131 int __attribute__((target("arch=sandybridge"))) bad_overload2(void);
133 // expected-error@+2 {{attribute 'target' multiversioning cannot be combined with attribute 'overloadable'}}
134 // expected-note@+2 {{function multiversioning caused by this declaration}}
135 int __attribute__((__overloadable__
)) __attribute__((target("sse4.2"))) bad_overload3(void);
136 int __attribute__((target("arch=sandybridge"))) bad_overload3(void);
138 int __attribute__((target("sse4.2"))) bad_overload4(void);
139 // expected-error@+1 {{attribute 'target' multiversioning cannot be combined with attribute 'overloadable'}}
140 int __attribute__((__overloadable__
)) __attribute__((target("arch=sandybridge"))) bad_overload4(void);
142 int __attribute__((target("sse4.2"))) bad_overload5(void);
143 int __attribute__((target("arch=sandybridge"))) bad_overload5(int);
145 int __attribute__((target("sse4.2"))) good_overload1(void);
146 int __attribute__((target("arch=sandybridge"))) good_overload1(void);
147 int __attribute__((__overloadable__
)) good_overload1(int);
149 int __attribute__((__overloadable__
)) good_overload2(int);
150 int __attribute__((target("sse4.2"))) good_overload2(void);
151 int __attribute__((target("arch=sandybridge"))) good_overload2(void);
153 // expected-error@+2 {{attribute 'target' multiversioning cannot be combined with attribute 'overloadable'}}
154 // expected-note@+2 {{function multiversioning caused by this declaration}}
155 int __attribute__((__overloadable__
)) __attribute__((target("sse4.2"))) good_overload3(void);
156 int __attribute__((__overloadable__
)) __attribute__((target("arch=sandybridge"))) good_overload3(void);
157 int good_overload3(int);
159 int good_overload4(int);
160 // expected-error@+2 {{attribute 'target' multiversioning cannot be combined with attribute 'overloadable'}}
161 // expected-note@+2 {{function multiversioning caused by this declaration}}
162 int __attribute__((__overloadable__
)) __attribute__((target("sse4.2"))) good_overload4(void);
163 int __attribute__((__overloadable__
)) __attribute__((target("arch=sandybridge"))) good_overload4(void);
165 int __attribute__((__overloadable__
)) __attribute__((target("sse4.2"))) good_overload5(void);
166 int __attribute__((__overloadable__
)) __attribute__((target("arch=sandybridge"))) good_overload5(int);
168 int __attribute__((target("sse4.2"))) good_overload6(void);
169 int __attribute__((__overloadable__
)) __attribute__((target("arch=sandybridge"))) good_overload6(int);
171 int __attribute__((__overloadable__
)) __attribute__((target("sse4.2"))) good_overload7(void);
172 int __attribute__((target("arch=sandybridge"))) good_overload7(int);