xref: /llvm-project/clang/test/Sema/aarch64-sve-lax-vector-conversions.c (revision 123064dc397d478a636ba1c5960d41ad381036a0)
1 // RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve -mvscale-min=4 -mvscale-max=4 -flax-vector-conversions=none -ffreestanding -fsyntax-only -verify=lax-vector-none %s
2 // RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve -mvscale-min=4 -mvscale-max=4 -flax-vector-conversions=integer -ffreestanding -fsyntax-only -verify=lax-vector-integer %s
3 // RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve -mvscale-min=4 -mvscale-max=4 -flax-vector-conversions=all -ffreestanding -fsyntax-only -verify=lax-vector-all %s
4 
5 // lax-vector-all-no-diagnostics
6 
7 // REQUIRES: aarch64-registered-target || arm-registered-target
8 
9 #include <arm_sve.h>
10 
11 #define N __ARM_FEATURE_SVE_BITS
12 #define SVE_FIXED_ATTR __attribute__((arm_sve_vector_bits(N)))
13 #define GNU_FIXED_ATTR __attribute__((vector_size(N / 8)))
14 
15 typedef svfloat32_t sve_fixed_float32_t SVE_FIXED_ATTR;
16 typedef svint32_t sve_fixed_int32_t SVE_FIXED_ATTR;
17 typedef float gnu_fixed_float32_t GNU_FIXED_ATTR;
18 typedef int gnu_fixed_int32_t GNU_FIXED_ATTR;
19 
sve_allowed_with_integer_lax_conversions()20 void sve_allowed_with_integer_lax_conversions() {
21   sve_fixed_int32_t fi32;
22   svint64_t si64;
23 
24   // The implicit cast here should fail if -flax-vector-conversions=none, but pass if
25   // -flax-vector-conversions={integer,all}.
26   fi32 = si64;
27   // lax-vector-none-error@-1 {{assigning to 'sve_fixed_int32_t' (vector of 16 'int' values) from incompatible type}}
28   si64 = fi32;
29   // lax-vector-none-error@-1 {{assigning to 'svint64_t' (aka '__SVInt64_t') from incompatible type}}
30 }
31 
sve_allowed_with_all_lax_conversions()32 void sve_allowed_with_all_lax_conversions() {
33   sve_fixed_float32_t ff32;
34   svfloat64_t sf64;
35 
36   // The implicit cast here should fail if -flax-vector-conversions={none,integer}, but pass if
37   // -flax-vector-conversions=all.
38   ff32 = sf64;
39   // lax-vector-none-error@-1 {{assigning to 'sve_fixed_float32_t' (vector of 16 'float' values) from incompatible type}}
40   // lax-vector-integer-error@-2 {{assigning to 'sve_fixed_float32_t' (vector of 16 'float' values) from incompatible type}}
41   sf64 = ff32;
42   // lax-vector-none-error@-1 {{assigning to 'svfloat64_t' (aka '__SVFloat64_t') from incompatible type}}
43   // lax-vector-integer-error@-2 {{assigning to 'svfloat64_t' (aka '__SVFloat64_t') from incompatible type}}
44 }
45 
gnu_allowed_with_integer_lax_conversions()46 void gnu_allowed_with_integer_lax_conversions() {
47   gnu_fixed_int32_t fi32;
48   svint64_t si64;
49 
50   // The implicit cast here should fail if -flax-vector-conversions=none, but pass if
51   // -flax-vector-conversions={integer,all}.
52   fi32 = si64;
53   // lax-vector-none-error@-1 {{assigning to 'gnu_fixed_int32_t' (vector of 16 'int' values) from incompatible type}}
54   si64 = fi32;
55   // lax-vector-none-error@-1 {{assigning to 'svint64_t' (aka '__SVInt64_t') from incompatible type}}
56 }
57 
gnu_allowed_with_all_lax_conversions()58 void gnu_allowed_with_all_lax_conversions() {
59   gnu_fixed_float32_t ff32;
60   svfloat64_t sf64;
61 
62   // The implicit cast here should fail if -flax-vector-conversions={none,integer}, but pass if
63   // -flax-vector-conversions=all.
64   ff32 = sf64;
65   // lax-vector-none-error@-1 {{assigning to 'gnu_fixed_float32_t' (vector of 16 'float' values) from incompatible type}}
66   // lax-vector-integer-error@-2 {{assigning to 'gnu_fixed_float32_t' (vector of 16 'float' values) from incompatible type}}
67   sf64 = ff32;
68   // lax-vector-none-error@-1 {{assigning to 'svfloat64_t' (aka '__SVFloat64_t') from incompatible type}}
69   // lax-vector-integer-error@-2 {{assigning to 'svfloat64_t' (aka '__SVFloat64_t') from incompatible type}}
70 }
71