xref: /llvm-project/clang/test/SemaCXX/attr-target-version.cpp (revision 6586c676b42aa9c7e78f9b1d419767a02793a70f)
1 // RUN: %clang_cc1 -triple aarch64-linux-gnu  -fsyntax-only -verify -fexceptions -fcxx-exceptions %s -std=c++14
2 void __attribute__((target_version("default"))) wrong_tv(void);
3 //expected-warning@+1 {{unsupported 'vmull' in the 'target_version' attribute string; 'target_version' attribute ignored}}
4 void __attribute__((target_version("vmull"))) wrong_tv(void);
5 
6 void __attribute__((target_version("dotprod"))) no_def(void);
7 void __attribute__((target_version("rdm+fp"))) no_def(void);
8 void __attribute__((target_version("rcpc3"))) no_def(void);
9 void __attribute__((target_version("mops"))) no_def(void);
10 void __attribute__((target_version("rdma"))) no_def(void);
11 
12 void foo(void) { no_def(); }
13 
14 constexpr int __attribute__((target_version("sve2"))) diff_const(void) { return 1; }
15 //expected-error@+1 {{multiversioned function declaration has a different constexpr specification}}
16 int __attribute__((target_version("sve2-bitperm"))) diff_const(void);
17 
18 int __attribute__((target_version("fp"))) diff_const1(void) { return 1; }
19 //expected-error@+1 {{multiversioned function declaration has a different constexpr specification}}
20 constexpr int __attribute__((target_version("sve2-aes"))) diff_const1(void);
21 
22 static int __attribute__((target_version("sve2-sha3"))) diff_link(void) { return 1; }
23 //expected-error@+1 {{multiversioned function declaration has a different linkage}}
24 int __attribute__((target_version("dpb"))) diff_link(void);
25 
26 int __attribute__((target_version("memtag"))) diff_link1(void) { return 1; }
27 //expected-error@+1 {{multiversioned function declaration has a different linkage}}
28 static int __attribute__((target_version("bti"))) diff_link1(void);
29 
30 int __attribute__((target_version("flagm2"))) diff_link2(void) { return 1; }
31 extern int __attribute__((target_version("flagm"))) diff_link2(void);
32 
33 namespace {
34 static int __attribute__((target_version("memtag"))) diff_link2(void) { return 2; }
35 int __attribute__((target_version("sve2-bitperm"))) diff_link2(void) { return 1; }
36 } // namespace
37 
38 inline int __attribute__((target_version("sme"))) diff_inline(void) { return 1; }
39 //expected-error@+1 {{multiversioned function declaration has a different inline specification}}
40 int __attribute__((target_version("fp16"))) diff_inline(void) { return 2; }
41 
42 inline int __attribute__((target_version("sme"))) diff_inline1(void) { return 1; }
43 //expected-error@+1 {{multiversioned function declaration has a different inline specification}}
44 int __attribute__((target_version("default"))) diff_inline1(void) { return 2; }
45 
46 int __attribute__((target_version("fcma"))) diff_type1(void) { return 1; }
47 //expected-error@+1 {{multiversioned function declaration has a different return type}}
48 double __attribute__((target_version("rcpc"))) diff_type1(void);
49 
50 auto __attribute__((target_version("rcpc2"))) diff_type2(void) -> int { return 1; }
51 //expected-error@+1 {{multiversioned function declaration has a different return type}}
52 auto __attribute__((target_version("bf16"))) diff_type2(void) -> long { return (long)1; }
53 
54 int __attribute__((target_version("fp16fml"))) diff_type3(void) noexcept(false) { return 1; }
55 //expected-error@+2 {{exception specification in declaration does not match previous declaration}}
56 //expected-note@-2 {{previous declaration is here}}
57 int __attribute__((target_version("sve2-sha3"))) diff_type3(void) noexcept(true) { return 2; }
58 
59 template <typename T> int __attribute__((target_version("default"))) temp(T) { return 1; }
60 // expected-error@-1 {{attribute 'target_version' multiversioned functions do not yet support function templates}}
61 template <typename T> int __attribute__((target_version("simd"))) temp1(T) { return 1; }
62 // expected-error@-1 {{attribute 'target_version' multiversioned functions do not yet support function templates}}
63 
64 extern "C" {
65 int __attribute__((target_version("aes"))) extc(void) { return 1; }
66 }
67 //expected-error@+1 {{multiversioned function declaration has a different language linkage}}
68 int __attribute__((target_version("lse"))) extc(void) { return 1; }
69 
70 auto __attribute__((target_version("default"))) ret1(void) { return 1; }
71 // expected-error@-1 {{attribute 'target_version' multiversioned functions do not yet support deduced return types}}
72 auto __attribute__((target_version("dpb"))) ret2(void) { return 1; }
73 // expected-error@-1 {{attribute 'target_version' multiversioned functions do not yet support deduced return types}}
74 auto __attribute__((target_version("dpb2"))) ret3(void) -> int { return 1; }
75 
76 class Cls {
77   __attribute__((target_version("rng"))) Cls();
78   // expected-error@-1 {{attribute 'target_version' multiversioned functions do not yet support constructors}}
79   __attribute__((target_version("i8mm"))) ~Cls();
80   // expected-error@-1 {{attribute 'target_version' multiversioned functions do not yet support destructors}}
81 
82   Cls &__attribute__((target_version("f32mm"))) operator=(const Cls &) = default;
83   // expected-error@-1 {{attribute 'target_version' multiversioned functions do not yet support defaulted functions}}
84   Cls &__attribute__((target_version("ssbs"))) operator=(Cls &&) = delete;
85   // expected-error@-1 {{attribute 'target_version' multiversioned functions do not yet support deleted functions}}
86 
87   virtual void __attribute__((target_version("default"))) vfunc();
88   // expected-error@-1 {{attribute 'target_version' multiversioned functions do not yet support virtual functions}}
89   virtual void __attribute__((target_version("sm4"))) vfunc1();
90   // expected-error@-1 {{attribute 'target_version' multiversioned functions do not yet support virtual functions}}
91 };
92 
93 __attribute__((target_version("sha3"))) void Decl();
94 namespace Nms {
95 using ::Decl;
96 // expected-error@+3 {{declaration conflicts with target of using declaration already in scope}}
97 // expected-note@-4 {{target of using declaration}}
98 // expected-note@-3 {{using declaration}}
99 __attribute__((target_version("jscvt"))) void Decl();
100 } // namespace Nms
101 
102 class Out { // #defined-here
103   int __attribute__((target_version("bti"))) func(void);
104   int __attribute__((target_version("ssbs"))) func(void);
105 };
106 int __attribute__((target_version("bti"))) Out::func(void) { return 1; }
107 int __attribute__((target_version("ssbs"))) Out::func(void) { return 2; }
108 // expected-error@+4 {{out-of-line definition of 'func' does not match any declaration in 'Out'}}
109 // expected-note@-2 {{member declaration nearly matches}}
110 // expected-note@-4 {{member declaration nearly matches}}
111 // expected-note@#defined-here {{defined here}}
112 int __attribute__((target_version("rng"))) Out::func(void) { return 3; }
113