1  /* { dg-options "-std=gnu99" } */
       2  
       3  #include <arm_sve.h>
       4  
       5  typedef signed char int8x32_t __attribute__((__vector_size__ (32)));
       6  
       7  /* Sizeless objects with global scope.  */
       8  
       9  svint8_t global_sve_sc; /* { dg-error {SVE type 'svint8_t' does not have a fixed size} } */
      10  static svint8_t local_sve_sc; /* { dg-error {SVE type 'svint8_t' does not have a fixed size} } */
      11  extern svint8_t extern_sve_sc; /* { dg-error {SVE type 'svint8_t' does not have a fixed size} } */
      12  __thread svint8_t tls_sve_sc; /* { dg-error {variables of type 'svint8_t' cannot have thread-local storage duration} } */
      13  _Atomic svint8_t atomic_sve_sc; /* { dg-error {SVE type 'svint8_t' does not have a fixed size} } */
      14  
      15  /* Sizeless arrays.  */
      16  
      17  typedef svint8_t array_type[2]; /* { dg-error {array elements cannot have SVE type 'svint8_t'} } */
      18  extern svint8_t extern_array[]; /* { dg-error {array elements cannot have SVE type 'svint8_t'} } */
      19  
      20  /* Sizeless fields.  */
      21  
      22  struct struct1 {
      23    svint8_t a; /* { dg-error {fields cannot have SVE type 'svint8_t'} } */
      24  };
      25  
      26  union union1 {
      27    svint8_t a; /* { dg-error {fields cannot have SVE type 'svint8_t'} } */
      28  };
      29  
      30  /* Pointers to sizeless types.  */
      31  
      32  svint8_t *global_sve_sc_ptr;
      33  svint8_t *invalid_sve_sc_ptr = &(svint8_t) {};  /* { dg-error {SVE type 'svint8_t' does not have a fixed size} } */
      34  
      35  /* Sizeless arguments and return values.  */
      36  
      37  void ext_consume_sve_sc (svint8_t);
      38  void ext_consume_varargs (int, ...);
      39  svint8_t ext_produce_sve_sc ();
      40  
      41  /* Main tests for statements and expressions.  */
      42  
      43  void
      44  statements (int n)
      45  {
      46    /* Local declarations.  */
      47  
      48    unsigned char va __attribute__((__vector_size__(2)));
      49    svint8_t sve_sc1, sve_sc2;
      50    _Atomic svint8_t atomic_sve_sc;
      51    int8x32_t gnu_sc1;
      52    svint16_t sve_sh1;
      53    static svint8_t local_static_sve_sc; /* { dg-error {SVE type 'svint8_t' does not have a fixed size} } */
      54  
      55    /* Layout queries.  */
      56  
      57    sizeof (svint8_t); /* { dg-error {SVE type 'svint8_t' does not have a fixed size} } */
      58    sizeof (sve_sc1); /* { dg-error {SVE type 'svint8_t' does not have a fixed size} } */
      59    sizeof (ext_produce_sve_sc ()); /* { dg-error {SVE type 'svint8_t' does not have a fixed size} } */
      60    _Alignof (svint8_t); /* { dg-error {SVE type 'svint8_t' does not have a defined alignment} } */
      61    _Alignof (sve_sc1); /* { dg-error {SVE type 'svint8_t' does not have a defined alignment} } */
      62    _Alignof (ext_produce_sve_sc ()); /* { dg-error {SVE type 'svint8_t' does not have a defined alignment} } */
      63  
      64    /* Initialization.  */
      65  
      66    svint8_t init_sve_sc1 = sve_sc1;
      67    svint8_t init_sve_sc2 = sve_sh1; /* { dg-error {incompatible types when initializing type 'svint8_t' using type 'svint16_t'} } */
      68    svint8_t init_sve_sc3 = {};
      69  
      70    int initi_a = sve_sc1; /* { dg-error {incompatible types when initializing type 'int' using type 'svint8_t'} } */
      71    int initi_b = { sve_sc1 }; /* { dg-error {incompatible types when initializing type 'int' using type 'svint8_t'} } */
      72  
      73    /* Compound literals.  */
      74  
      75    (svint8_t) {};
      76    (svint8_t) { sve_sc1 };
      77  
      78    (int) { sve_sc1 }; /* { dg-error {incompatible types when initializing type 'int' using type 'svint8_t'} } */
      79  
      80    /* Arrays.  */
      81  
      82    svint8_t array[2]; /* { dg-error {array elements cannot have SVE type 'svint8_t'} } */
      83    svint8_t zero_length_array[0]; /* { dg-error {array elements cannot have SVE type 'svint8_t'} } */
      84    svint8_t empty_init_array[] = {}; /* { dg-error {array elements cannot have SVE type 'svint8_t'} } */
      85    typedef svint8_t vla_type[n]; /* { dg-error {array elements cannot have SVE type 'svint8_t'} } */
      86  
      87    /* Assignment.  */
      88  
      89    n = sve_sc1; /* { dg-error {incompatible types when assigning to type 'int' from type 'svint8_t'} } */
      90  
      91    sve_sc1 = 0; /* { dg-error {incompatible types when assigning to type 'svint8_t' from type 'int'} } */
      92    sve_sc1 = sve_sc2;
      93    sve_sc1 = sve_sh1; /* { dg-error {incompatible types when assigning to type 'svint8_t' from type 'svint16_t'} } */
      94  
      95    /* Casting.  */
      96  
      97    (void) sve_sc1;
      98    (svint8_t) sve_sc1;
      99  
     100    /* Addressing and dereferencing.  */
     101  
     102    svint8_t *sve_sc_ptr = &sve_sc1;
     103    int8x32_t *gnu_sc_ptr = &gnu_sc1;
     104    sve_sc1 = *sve_sc_ptr;
     105  
     106    /* Pointer assignment.  */
     107  
     108    gnu_sc_ptr = sve_sc_ptr; /* { dg-warning {assignment to [^\n]* from incompatible pointer type} } */
     109    sve_sc_ptr = gnu_sc_ptr; /* { dg-warning {assignment to [^\n]* from incompatible pointer type} } */
     110  
     111    /* Pointer arithmetic.  */
     112  
     113    ++sve_sc_ptr; /* { dg-error {arithmetic on pointer to SVE type 'svint8_t'} } */
     114    --sve_sc_ptr; /* { dg-error {arithmetic on pointer to SVE type 'svint8_t'} } */
     115    sve_sc_ptr++; /* { dg-error {arithmetic on pointer to SVE type 'svint8_t'} } */
     116    sve_sc_ptr--; /* { dg-error {arithmetic on pointer to SVE type 'svint8_t'} } */
     117    sve_sc_ptr += 0; /* { dg-error {arithmetic on pointer to SVE type 'svint8_t'} } */
     118    sve_sc_ptr += 1; /* { dg-error {arithmetic on pointer to SVE type 'svint8_t'} } */
     119    sve_sc_ptr -= 0; /* { dg-error {arithmetic on pointer to SVE type 'svint8_t'} } */
     120    sve_sc_ptr -= 1; /* { dg-error {arithmetic on pointer to SVE type 'svint8_t'} } */
     121    sve_sc_ptr - sve_sc_ptr; /* { dg-error {arithmetic on pointer to SVE type 'svint8_t'} } */
     122    gnu_sc_ptr - sve_sc_ptr; /* { dg-error {invalid operands to binary -} } */
     123    sve_sc_ptr - gnu_sc_ptr; /* { dg-error {invalid operands to binary -} } */
     124    sve_sc1 = sve_sc_ptr[0]; /* { dg-error {arithmetic on pointer to SVE type 'svint8_t'} } */
     125    sve_sc1 = sve_sc_ptr[1]; /* { dg-error {arithmetic on pointer to SVE type 'svint8_t'} } */
     126  
     127    /* Pointer comparison.  */
     128  
     129    sve_sc_ptr == &sve_sc1;
     130    sve_sc_ptr != &sve_sc1;
     131    sve_sc_ptr < &sve_sc1;
     132    sve_sc_ptr <= &sve_sc1;
     133    sve_sc_ptr > &sve_sc1;
     134    sve_sc_ptr >= &sve_sc1;
     135    gnu_sc_ptr == sve_sc_ptr; /* { dg-warning {comparison of distinct pointer types lacks a cast} } */
     136    gnu_sc_ptr != sve_sc_ptr; /* { dg-warning {comparison of distinct pointer types lacks a cast} } */
     137    gnu_sc_ptr < sve_sc_ptr; /* { dg-warning {comparison of distinct pointer types lacks a cast} } */
     138    gnu_sc_ptr <= sve_sc_ptr; /* { dg-warning {comparison of distinct pointer types lacks a cast} } */
     139    gnu_sc_ptr > sve_sc_ptr; /* { dg-warning {comparison of distinct pointer types lacks a cast} } */
     140    gnu_sc_ptr >= sve_sc_ptr; /* { dg-warning {comparison of distinct pointer types lacks a cast} } */
     141    sve_sc_ptr == gnu_sc_ptr; /* { dg-warning {comparison of distinct pointer types lacks a cast} } */
     142    sve_sc_ptr != gnu_sc_ptr; /* { dg-warning {comparison of distinct pointer types lacks a cast} } */
     143    sve_sc_ptr < gnu_sc_ptr; /* { dg-warning {comparison of distinct pointer types lacks a cast} } */
     144    sve_sc_ptr <= gnu_sc_ptr; /* { dg-warning {comparison of distinct pointer types lacks a cast} } */
     145    sve_sc_ptr > gnu_sc_ptr; /* { dg-warning {comparison of distinct pointer types lacks a cast} } */
     146    sve_sc_ptr >= gnu_sc_ptr; /* { dg-warning {comparison of distinct pointer types lacks a cast} } */
     147  
     148    /* Conditional expressions.  */
     149  
     150    0 ? sve_sc1 : sve_sc1;
     151    0 ? sve_sc1 : sve_sh1; /* { dg-error {type mismatch in conditional expression} } */
     152    0 ? sve_sc1 : 0; /* { dg-error {type mismatch in conditional expression} } */
     153    0 ? 0 : sve_sc1; /* { dg-error {type mismatch in conditional expression} } */
     154    0 ?: sve_sc1; /* { dg-error {type mismatch in conditional expression} } */
     155    0 ? sve_sc_ptr : sve_sc_ptr;
     156    0 ? sve_sc_ptr : gnu_sc_ptr; /* { dg-warning {pointer type mismatch in conditional expression} } */
     157    0 ? gnu_sc_ptr : sve_sc_ptr; /* { dg-warning {pointer type mismatch in conditional expression} } */
     158  
     159    /* Generic associations.  */
     160  
     161    _Generic (sve_sc1, default: 100);
     162    _Generic (1, svint8_t: 10, default: 20);
     163  
     164    /* Function arguments.  */
     165  
     166    ext_consume_sve_sc (sve_sc1);
     167    ext_consume_sve_sc (sve_sh1); /* { dg-error {incompatible type for argument 1 of 'ext_consume_sve_sc'} } */
     168    ext_consume_varargs (sve_sc1); /* { dg-error {incompatible type for argument 1 of 'ext_consume_varargs'} } */
     169    ext_consume_varargs (1, sve_sc1);
     170  
     171    /* Function returns.  */
     172  
     173    ext_produce_sve_sc ();
     174    sve_sc1 = ext_produce_sve_sc ();
     175    sve_sh1 = ext_produce_sve_sc (); /* { dg-error {incompatible types when assigning to type 'svint16_t' from type 'svint8_t'} } */
     176  
     177    /* Varargs processing.  */
     178  
     179    __builtin_va_list valist;
     180    __builtin_va_arg (valist, svint8_t);
     181  
     182    /* Statement expressions.  */
     183  
     184    ({ sve_sc1; });
     185    ({ svint8_t another_sve_sc = *sve_sc_ptr; another_sve_sc; });
     186  }
     187  
     188  /* Function parameters in definitions.  */
     189  
     190  void
     191  old_style (input_sve_sc) /* { dg-error {SVE type 'svint8_t' cannot be passed to an unprototyped function} } */
     192       svint8_t input_sve_sc;
     193  {
     194    svint8_t sve_sc1 = input_sve_sc;
     195  }
     196  
     197  void
     198  new_style_param (svint8_t input_sve_sc)
     199  {
     200    svint8_t sve_sc1 = input_sve_sc;
     201  }
     202  
     203  /* Function return values in definitions.  */
     204  
     205  svint8_t
     206  good_return_sve_sc (svint8_t param)
     207  {
     208    return param;
     209  }
     210  
     211  svint8_t
     212  bad_return_sve_sc (svint16_t param)
     213  {
     214    return param; /* { dg-error {incompatible types when returning type 'svint16_t' but 'svint8_t' was expected} } */
     215  }