1 // RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve -msve-vector-bits=512 -flax-vector-conversions=none -fallow-half-arguments-and-returns -ffreestanding -fsyntax-only -verify=lax-vector-none %s
2 // RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve -msve-vector-bits=512 -flax-vector-conversions=integer -fallow-half-arguments-and-returns -ffreestanding -fsyntax-only -verify=lax-vector-integer %s
3 // RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve -msve-vector-bits=512 -flax-vector-conversions=all -fallow-half-arguments-and-returns -ffreestanding -fsyntax-only -verify=lax-vector-all %s
4 
5 #include <arm_sve.h>
6 
7 #define N __ARM_FEATURE_SVE_BITS
8 #define SVE_FIXED_ATTR __attribute__((arm_sve_vector_bits(N)))
9 #define GNU_FIXED_ATTR __attribute__((vector_size(N / 8)))
10 #define GNU_BOOL_FIXED_ATTR __attribute__((vector_size(N / 64)))
11 
12 typedef svfloat32_t sve_fixed_float32_t SVE_FIXED_ATTR;
13 typedef svint32_t sve_fixed_int32_t SVE_FIXED_ATTR;
14 typedef svbool_t sve_fixed_bool_t SVE_FIXED_ATTR;
15 typedef float gnu_fixed_float32_t GNU_FIXED_ATTR;
16 typedef int gnu_fixed_int32_t GNU_FIXED_ATTR;
17 typedef int8_t gnu_fixed_bool_t GNU_BOOL_FIXED_ATTR;
18 
sve_allowed_with_integer_lax_conversions()19 void sve_allowed_with_integer_lax_conversions() {
20   sve_fixed_int32_t fi32;
21   svint64_t si64;
22   svbool_t sb8;
23   sve_fixed_bool_t fb8;
24 
25   // The implicit cast here should fail if -flax-vector-conversions=none, but pass if
26   // -flax-vector-conversions={integer,all}.
27   fi32 = si64;
28   // lax-vector-none-error@-1 {{assigning to 'sve_fixed_int32_t' (vector of 16 'int' values) from incompatible type}}
29   si64 = fi32;
30   // lax-vector-none-error@-1 {{assigning to 'svint64_t' (aka '__SVInt64_t') from incompatible type}}
31 
32   fi32 = sb8;
33   // lax-vector-none-error@-1 {{assigning to 'sve_fixed_int32_t' (vector of 16 'int' values) from incompatible type}}
34   // lax-vector-integer-error@-2 {{assigning to 'sve_fixed_int32_t' (vector of 16 'int' values) from incompatible type}}
35   // lax-vector-all-error@-3 {{assigning to 'sve_fixed_int32_t' (vector of 16 'int' values) from incompatible type}}
36   sb8 = fi32;
37   // lax-vector-none-error@-1 {{assigning to 'svbool_t' (aka '__SVBool_t') from incompatible type}}
38   // lax-vector-integer-error@-2 {{assigning to 'svbool_t' (aka '__SVBool_t') from incompatible type}}
39   // lax-vector-all-error@-3 {{assigning to 'svbool_t' (aka '__SVBool_t') from incompatible type}}
40 
41   si64 = fb8;
42   // lax-vector-none-error@-1 {{assigning to 'svint64_t' (aka '__SVInt64_t') from incompatible type}}
43   // lax-vector-integer-error@-2 {{assigning to 'svint64_t' (aka '__SVInt64_t') from incompatible type}}
44   // lax-vector-all-error@-3 {{assigning to 'svint64_t' (aka '__SVInt64_t') from incompatible type}}
45 
46   fb8 = si64;
47   // lax-vector-none-error@-1 {{assigning to 'sve_fixed_bool_t' (vector of 8 'unsigned char' values) from incompatible type}}
48   // lax-vector-integer-error@-2 {{assigning to 'sve_fixed_bool_t' (vector of 8 'unsigned char' values) from incompatible type}}
49   // lax-vector-all-error@-3 {{assigning to 'sve_fixed_bool_t' (vector of 8 'unsigned char' values) from incompatible type}}
50 }
51 
sve_allowed_with_all_lax_conversions()52 void sve_allowed_with_all_lax_conversions() {
53   sve_fixed_float32_t ff32;
54   svfloat64_t sf64;
55 
56   // The implicit cast here should fail if -flax-vector-conversions={none,integer}, but pass if
57   // -flax-vector-conversions=all.
58   ff32 = sf64;
59   // lax-vector-none-error@-1 {{assigning to 'sve_fixed_float32_t' (vector of 16 'float' values) from incompatible type}}
60   // lax-vector-integer-error@-2 {{assigning to 'sve_fixed_float32_t' (vector of 16 'float' values) from incompatible type}}
61   sf64 = ff32;
62   // lax-vector-none-error@-1 {{assigning to 'svfloat64_t' (aka '__SVFloat64_t') from incompatible type}}
63   // lax-vector-integer-error@-2 {{assigning to 'svfloat64_t' (aka '__SVFloat64_t') from incompatible type}}
64 }
65 
gnu_allowed_with_integer_lax_conversions()66 void gnu_allowed_with_integer_lax_conversions() {
67   gnu_fixed_int32_t fi32;
68   svint64_t si64;
69   svbool_t sb8;
70   gnu_fixed_bool_t fb8;
71 
72   // The implicit cast here should fail if -flax-vector-conversions=none, but pass if
73   // -flax-vector-conversions={integer,all}.
74   fi32 = si64;
75   // lax-vector-none-error@-1 {{assigning to 'gnu_fixed_int32_t' (vector of 16 'int' values) from incompatible type}}
76   si64 = fi32;
77   // lax-vector-none-error@-1 {{assigning to 'svint64_t' (aka '__SVInt64_t') from incompatible type}}
78 
79   fi32 = sb8;
80   // lax-vector-none-error@-1 {{assigning to 'gnu_fixed_int32_t' (vector of 16 'int' values) from incompatible type}}
81   // lax-vector-integer-error@-2 {{assigning to 'gnu_fixed_int32_t' (vector of 16 'int' values) from incompatible type}}
82   // lax-vector-all-error@-3 {{assigning to 'gnu_fixed_int32_t' (vector of 16 'int' values) from incompatible type}}
83   sb8 = fi32;
84   // lax-vector-none-error@-1 {{assigning to 'svbool_t' (aka '__SVBool_t') from incompatible type}}
85   // lax-vector-integer-error@-2 {{assigning to 'svbool_t' (aka '__SVBool_t') from incompatible type}}
86   // lax-vector-all-error@-3 {{assigning to 'svbool_t' (aka '__SVBool_t') from incompatible type}}
87 
88   fb8 = si64;
89   // lax-vector-none-error@-1 {{assigning to 'gnu_fixed_bool_t' (vector of 8 'int8_t' values) from incompatible type}}
90   // lax-vector-integer-error@-2 {{assigning to 'gnu_fixed_bool_t' (vector of 8 'int8_t' values) from incompatible type}}
91   // lax-vector-all-error@-3 {{assigning to 'gnu_fixed_bool_t' (vector of 8 'int8_t' values) from incompatible type}}
92   si64 = fb8;
93   // lax-vector-none-error@-1 {{assigning to 'svint64_t' (aka '__SVInt64_t') from incompatible type}}
94   // lax-vector-integer-error@-2 {{assigning to 'svint64_t' (aka '__SVInt64_t') from incompatible type}}
95   // lax-vector-all-error@-3 {{assigning to 'svint64_t' (aka '__SVInt64_t') from incompatible type}}
96 }
97 
gnu_allowed_with_all_lax_conversions()98 void gnu_allowed_with_all_lax_conversions() {
99   gnu_fixed_float32_t ff32;
100   svfloat64_t sf64;
101 
102   // The implicit cast here should fail if -flax-vector-conversions={none,integer}, but pass if
103   // -flax-vector-conversions=all.
104   ff32 = sf64;
105   // lax-vector-none-error@-1 {{assigning to 'gnu_fixed_float32_t' (vector of 16 'float' values) from incompatible type}}
106   // lax-vector-integer-error@-2 {{assigning to 'gnu_fixed_float32_t' (vector of 16 'float' values) from incompatible type}}
107   sf64 = ff32;
108   // lax-vector-none-error@-1 {{assigning to 'svfloat64_t' (aka '__SVFloat64_t') from incompatible type}}
109   // lax-vector-integer-error@-2 {{assigning to 'svfloat64_t' (aka '__SVFloat64_t') from incompatible type}}
110 }
111