| 1 |
// RUN: %clang_cc1 -triple x86_64-linux-gnu -Wno-strict-prototypes -fsyntax-only -verify %s |
| 2 |
|
| 3 |
void __attribute__((target("sse4.2"))) no_default(void); |
| 4 |
void __attribute__((target("arch=sandybridge"))) no_default(void); |
| 5 |
|
| 6 |
void use1(void){ |
| 7 |
// expected-error@+1 {{no matching function for call to 'no_default'}} |
| 8 |
no_default(); |
| 9 |
} |
| 10 |
|
| 11 |
void __attribute__((target("sse4.2"))) has_def(void); |
| 12 |
void __attribute__((target("default"))) has_def(void); |
| 13 |
|
| 14 |
void use2(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}} |
| 17 |
+has_def; |
| 18 |
} |
| 19 |
|
| 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(); |
| 24 |
|
| 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; } |
| 29 |
|
| 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; } |
| 33 |
|
| 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; } |
| 38 |
|
| 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); |
| 42 |
|
| 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; } |
| 49 |
|
| 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;} |
| 54 |
|
| 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; } |
| 63 |
|
| 64 |
int __attribute__((target("sse4.2"))) mv_after_use(void) { return 1; } |
| 65 |
int use3(void) { |
| 66 |
return mv_after_use(); |
| 67 |
} |
| 68 |
|
| 69 |
// expected-error@+2 {{function declaration cannot become a multiversioned function after first usage}} |
| 70 |
// expected-note@-6 {{previous declaration is here}} |
| 71 |
int __attribute__((target("arch=sandybridge"))) mv_after_use(void) { return 2; } |
| 72 |
|
| 73 |
int __attribute__((target("sse4.2,arch=sandybridge"))) mangle(void) { return 1; } |
| 74 |
//expected-error@+2 {{multiversioned function redeclarations require identical target attributes}} |
| 75 |
//expected-note@-2 {{previous declaration is here}} |
| 76 |
int __attribute__((target("arch=sandybridge,sse4.2"))) mangle(void) { return 2; } |
| 77 |
|
| 78 |
// allow this, since we want to treat the 1st one as fwd-decl of the sandybridge version. |
| 79 |
int prev_no_target(void); |
| 80 |
int __attribute__((target("arch=sandybridge"))) prev_no_target(void) { return 2; } |
| 81 |
int __attribute__((target("arch=ivybridge"))) prev_no_target(void) { return 2; } |
| 82 |
|
| 83 |
int __attribute__((target("arch=sandybridge"))) prev_no_target2(void); |
| 84 |
int prev_no_target2(void); |
| 85 |
// expected-error@-1 {{function declaration is missing 'target' attribute in a multiversioned function}} |
| 86 |
// expected-note@+1 {{function multiversioning caused by this declaration}} |
| 87 |
int __attribute__((target("arch=ivybridge"))) prev_no_target2(void); |
| 88 |
|
| 89 |
void __attribute__((target("sse4.2"))) addtl_attrs(void); |
| 90 |
//expected-error@+2 {{attribute 'target' multiversioning cannot be combined with attribute 'no_caller_saved_registers'}} |
| 91 |
void __attribute__((no_caller_saved_registers,target("arch=sandybridge"))) |
| 92 |
addtl_attrs(void); |
| 93 |
|
| 94 |
//expected-error@+1 {{attribute 'target' multiversioning cannot be combined with attribute 'no_caller_saved_registers'}} |
| 95 |
void __attribute__((target("default"), no_caller_saved_registers)) addtl_attrs2(void); |
| 96 |
|
| 97 |
//expected-error@+2 {{attribute 'target' multiversioning cannot be combined with attribute 'no_caller_saved_registers'}} |
| 98 |
//expected-note@+2 {{function multiversioning caused by this declaration}} |
| 99 |
void __attribute__((no_caller_saved_registers,target("sse4.2"))) addtl_attrs3(void); |
| 100 |
void __attribute__((target("arch=sandybridge"))) addtl_attrs3(void); |
| 101 |
|
| 102 |
void __attribute__((target("sse4.2"))) addtl_attrs4(void); |
| 103 |
void __attribute__((target("arch=sandybridge"))) addtl_attrs4(void); |
| 104 |
//expected-error@+1 {{attribute 'target' multiversioning cannot be combined}} |
| 105 |
void __attribute__((no_caller_saved_registers,target("arch=ivybridge"))) addtl_attrs4(void); |
| 106 |
|
| 107 |
int __attribute__((target("sse4.2"))) diff_cc(void); |
| 108 |
// expected-error@+1 {{multiversioned function declaration has a different calling convention}} |
| 109 |
__vectorcall int __attribute__((target("arch=sandybridge"))) diff_cc(void); |
| 110 |
|
| 111 |
int __attribute__((target("sse4.2"))) diff_ret(void); |
| 112 |
// expected-error@+1 {{multiversioned function declaration has a different return type}} |
| 113 |
short __attribute__((target("arch=sandybridge"))) diff_ret(void); |
| 114 |
|
| 115 |
void __attribute__((target("sse4.2"), nothrow, used, nonnull(1))) addtl_attrs5(int*); |
| 116 |
void __attribute__((target("arch=sandybridge"))) addtl_attrs5(int*); |
| 117 |
|
| 118 |
void __attribute__((target("sse4.2"))) addtl_attrs6(int*); |
| 119 |
void __attribute__((target("arch=sandybridge"), nothrow, used, nonnull)) addtl_attrs6(int*); |
| 120 |
|
| 121 |
int __attribute__((target("sse4.2"))) bad_overload1(void); |
| 122 |
int __attribute__((target("arch=sandybridge"))) bad_overload1(void); |
| 123 |
// expected-error@+1 {{function declaration is missing 'target' attribute in a multiversioned function}} |
| 124 |
int bad_overload1(int); |
| 125 |
|
| 126 |
int bad_overload2(int); |
| 127 |
// expected-error@+2 {{conflicting types for 'bad_overload2'}} |
| 128 |
// expected-note@-2 {{previous declaration is here}} |
| 129 |
int __attribute__((target("sse4.2"))) bad_overload2(void); |
| 130 |
// expected-error@+2 {{conflicting types for 'bad_overload2'}} |
| 131 |
// expected-note@-5 {{previous declaration is here}} |
| 132 |
int __attribute__((target("arch=sandybridge"))) bad_overload2(void); |
| 133 |
|
| 134 |
// expected-error@+2 {{attribute 'target' multiversioning cannot be combined with attribute 'overloadable'}} |
| 135 |
// expected-note@+2 {{function multiversioning caused by this declaration}} |
| 136 |
int __attribute__((__overloadable__)) __attribute__((target("sse4.2"))) bad_overload3(void); |
| 137 |
int __attribute__((target("arch=sandybridge"))) bad_overload3(void); |
| 138 |
|
| 139 |
int __attribute__((target("sse4.2"))) bad_overload4(void); |
| 140 |
// expected-error@+1 {{attribute 'target' multiversioning cannot be combined with attribute 'overloadable'}} |
| 141 |
int __attribute__((__overloadable__)) __attribute__((target("arch=sandybridge"))) bad_overload4(void); |
| 142 |
|
| 143 |
int __attribute__((target("sse4.2"))) bad_overload5(void); |
| 144 |
int __attribute__((target("arch=sandybridge"))) bad_overload5(int); |
| 145 |
|
| 146 |
int __attribute__((target("sse4.2"))) good_overload1(void); |
| 147 |
int __attribute__((target("arch=sandybridge"))) good_overload1(void); |
| 148 |
int __attribute__((__overloadable__)) good_overload1(int); |
| 149 |
|
| 150 |
int __attribute__((__overloadable__)) good_overload2(int); |
| 151 |
int __attribute__((target("sse4.2"))) good_overload2(void); |
| 152 |
int __attribute__((target("arch=sandybridge"))) good_overload2(void); |
| 153 |
|
| 154 |
// expected-error@+2 {{attribute 'target' multiversioning cannot be combined with attribute 'overloadable'}} |
| 155 |
// expected-note@+2 {{function multiversioning caused by this declaration}} |
| 156 |
int __attribute__((__overloadable__)) __attribute__((target("sse4.2"))) good_overload3(void); |
| 157 |
int __attribute__((__overloadable__)) __attribute__((target("arch=sandybridge"))) good_overload3(void); |
| 158 |
int good_overload3(int); |
| 159 |
|
| 160 |
int good_overload4(int); |
| 161 |
// expected-error@+2 {{attribute 'target' multiversioning cannot be combined with attribute 'overloadable'}} |
| 162 |
// expected-note@+2 {{function multiversioning caused by this declaration}} |
| 163 |
int __attribute__((__overloadable__)) __attribute__((target("sse4.2"))) good_overload4(void); |
| 164 |
int __attribute__((__overloadable__)) __attribute__((target("arch=sandybridge"))) good_overload4(void); |
| 165 |
|
| 166 |
int __attribute__((__overloadable__)) __attribute__((target("sse4.2"))) good_overload5(void); |
| 167 |
int __attribute__((__overloadable__)) __attribute__((target("arch=sandybridge"))) good_overload5(int); |
| 168 |
|
| 169 |
int __attribute__((target("sse4.2"))) good_overload6(void); |
| 170 |
int __attribute__((__overloadable__)) __attribute__((target("arch=sandybridge"))) good_overload6(int); |
| 171 |
|
| 172 |
int __attribute__((__overloadable__)) __attribute__((target("sse4.2"))) good_overload7(void); |
| 173 |
int __attribute__((target("arch=sandybridge"))) good_overload7(int); |
| 174 |
|
| 175 |
// expected-error@+2 {{function multiversioning doesn't support feature 'sha'}} |
| 176 |
// expected-note@+2 {{function multiversioning caused by this declaration}} |
| 177 |
int __attribute__((target("sha"))) no_priority1(void); |
| 178 |
int __attribute__((target("default"))) no_priority1(void); |
| 179 |
|
| 180 |
int __attribute__((target("default"))) no_priority2(void); |
| 181 |
// expected-error@+1 {{function multiversioning doesn't support feature 'sha'}} |
| 182 |
int __attribute__((target("sha"))) no_priority2(void); |
| 183 |
|
| 184 |
int __attribute__((target("default"))) no_priority3(void); |
| 185 |
int __attribute__((target("avx2"))) no_priority3(void); |
| 186 |
// expected-error@+1 {{function multiversioning doesn't support feature 'sha'}} |
| 187 |
int __attribute__((target("sha"))) no_priority3(void); |