1 // RUN: %clang_cc1 -triple x86_64-linux-gnu  -fsyntax-only -verify %s
2 
3 void __attribute__((target("sse4.2"))) no_default(void);
4 void __attribute__((target("arch=sandybridge")))  no_default(void);
5 
use1(void)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 
use2(void)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);
redecl1(void)27 int __attribute__((target("sse4.2"))) redecl1(void) { return 1; }
redecl1(void)28 int __attribute__((target("arch=sandybridge")))  redecl1(void) { return 2; }
29 
redecl2(void)30 int __attribute__((target("sse4.2"))) redecl2(void) { return 1; }
31 int __attribute__((target("sse4.2"))) redecl2(void);
redecl2(void)32 int __attribute__((target("arch=sandybridge")))  redecl2(void) { return 2; }
33 
redecl3(void)34 int __attribute__((target("sse4.2"))) redecl3(void) { return 0; }
redecl3(void)35 int __attribute__((target("arch=ivybridge"))) redecl3(void) { return 1; }
36 int __attribute__((target("arch=sandybridge")))  redecl3(void);
redecl3(void)37 int __attribute__((target("arch=sandybridge")))  redecl3(void) { return 2; }
38 
redecl4(void)39 int __attribute__((target("sse4.2"))) redecl4(void) { return 1; }
redecl4(void)40 int __attribute__((target("arch=sandybridge")))  redecl4(void) { return 2; }
41 int __attribute__((target("arch=sandybridge")))  redecl4(void);
42 
redef(void)43 int __attribute__((target("sse4.2"))) redef(void) { return 1; }
redef(void)44 int __attribute__((target("arch=ivybridge"))) redef(void) { return 1; }
redef(void)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}}
redef(void)48 int __attribute__((target("arch=sandybridge")))  redef(void) { return 2; }
49 
redef2(void)50 int __attribute__((target("default"))) redef2(void) { return 1;}
51 // expected-error@+2 {{redefinition of 'redef2'}}
52 // expected-note@-2 {{previous definition is here}}
redef2(void)53 int __attribute__((target("default"))) redef2(void) { return 1;}
54 
mv_after_use(void)55 int __attribute__((target("sse4.2"))) mv_after_use(void) { return 1; }
use3(void)56 int use3(void) {
57   return mv_after_use();
58 }
59 
60 // expected-error@+1 {{function declaration cannot become a multiversioned function after first usage}}
mv_after_use(void)61 int __attribute__((target("arch=sandybridge")))  mv_after_use(void) { return 2; }
62 
mangle(void)63 int __attribute__((target("sse4.2,arch=sandybridge"))) mangle(void) { return 1; }
64 //expected-error@+2 {{multiversioned function redeclarations require identical target attributes}}
65 //expected-note@-2 {{previous declaration is here}}
mangle(void)66 int __attribute__((target("arch=sandybridge,sse4.2")))  mangle(void) { return 2; }
67 
68 // allow this, since we want to treat the 1st one as fwd-decl of the sandybridge version.
69 int prev_no_target(void);
prev_no_target(void)70 int __attribute__((target("arch=sandybridge")))  prev_no_target(void) { return 2; }
prev_no_target(void)71 int __attribute__((target("arch=ivybridge")))  prev_no_target(void) { return 2; }
72 
73 int __attribute__((target("arch=sandybridge")))  prev_no_target2(void);
74 int prev_no_target2(void);
75 // expected-error@-1 {{function declaration is missing 'target' attribute in a multiversioned function}}
76 // expected-note@+1 {{function multiversioning caused by this declaration}}
77 int __attribute__((target("arch=ivybridge")))  prev_no_target2(void);
78 
79 void __attribute__((target("sse4.2"))) addtl_attrs(void);
80 //expected-error@+2 {{attribute 'target' multiversioning cannot be combined}}
81 void __attribute__((no_caller_saved_registers,target("arch=sandybridge")))
82 addtl_attrs(void);
83 
84 //expected-error@+1 {{attribute 'target' multiversioning cannot be combined}}
85 void __attribute__((target("default"), no_caller_saved_registers)) addtl_attrs2(void);
86 
87 //expected-error@+2 {{attribute 'target' multiversioning cannot be combined}}
88 //expected-note@+2 {{function multiversioning caused by this declaration}}
89 void __attribute__((no_caller_saved_registers,target("sse4.2"))) addtl_attrs3(void);
90 void __attribute__((target("arch=sandybridge")))  addtl_attrs3(void);
91 
92 void __attribute__((target("sse4.2"))) addtl_attrs4(void);
93 void __attribute__((target("arch=sandybridge")))  addtl_attrs4(void);
94 //expected-error@+1 {{attribute 'target' multiversioning cannot be combined}}
95 void __attribute__((no_caller_saved_registers,target("arch=ivybridge")))  addtl_attrs4(void);
96 
97 int __attribute__((target("sse4.2"))) diff_cc(void);
98 // expected-error@+1 {{multiversioned function declaration has a different calling convention}}
99 __vectorcall int __attribute__((target("arch=sandybridge")))  diff_cc(void);
100 
101 int __attribute__((target("sse4.2"))) diff_ret(void);
102 // expected-error@+1 {{multiversioned function declaration has a different return type}}
103 short __attribute__((target("arch=sandybridge")))  diff_ret(void);
104