Home | History | Annotate | Download | only in SemaCXX
      1 // RUN: %clang_cc1 -fsyntax-only -verify %s
      2 
      3 typedef enum { XX } EnumType;
      4 struct S { int x; };
      5 
      6 // Check enumerations. Vector modes on enum types must cause an error.
      7 template <class T>
      8 void CheckEnumerations() {
      9   // Check that non-vector 'mode' attribute is OK with enumeration types.
     10   typedef T __attribute__((mode(QI))) T1;
     11   typedef T T2 __attribute__((mode(HI)));
     12   typedef T __attribute__((mode(V8SI))) T3; // expected-error{{mode 'V8SI' is not supported for enumeration types}}
     13   // expected-warning@-1{{specifying vector types with the 'mode' attribute is deprecated}}
     14 
     15   typedef enum __attribute__((mode(HI))) { A4, B4 } T4;
     16   typedef enum { A5, B5 } __attribute__((mode(SI))) T5;
     17   typedef enum __attribute__((mode(V2SI))) { A6, B6 } T6; // expected-error{{mode 'V2SI' is not supported for enumeration types}}
     18                                                           // expected-warning@-1{{deprecated}}
     19   typedef enum { A7, B7 } __attribute__((mode(V2QI))) T7; // expected-error{{mode 'V2QI' is not supported for enumeration types}}
     20                                                           // expected-warning@-1{{deprecated}}
     21 }
     22 
     23 // Check that attribute applies only for integer and floating-point types.
     24 // OK when instantiated with 'int', error with structure types, for example.
     25 template <class T>
     26 void CheckPrimitiveTypes() {
     27   typedef T __attribute__((mode(QI))) T1;    // expected-error{{mode attribute only supported for integer and floating-point types}}
     28   typedef T __attribute__((mode(V2SI))) VT1; // expected-error{{mode attribute only supported for integer and floating-point types}}
     29   // expected-warning@-1{{specifying vector types with the 'mode' attribute is deprecated}}
     30 }
     31 
     32 // Check that attribute supports certain modes. Check that wrong machine modes
     33 // are NOT diagnosed twice during instantiation.
     34 template <class T>
     35 void CheckMachineMode() {
     36   typedef T __attribute__((mode(QI))) T1; // expected-error{{type of machine mode does not match type of base type}}
     37   typedef T __attribute__((mode(HI))) T2; // expected-error{{type of machine mode does not match type of base type}}
     38   typedef T __attribute__((mode(SI))) T3; // expected-error{{type of machine mode does not match type of base type}}
     39   typedef T __attribute__((mode(DI))) T4; // expected-error{{type of machine mode does not match type of base type}}
     40   typedef T __attribute__((mode(SF))) T5; // expected-error2{{type of machine mode does not match type of base type}}
     41   typedef T __attribute__((mode(DF))) T6; // expected-error2{{type of machine mode does not match type of base type}}
     42   typedef T __attribute__((mode(II))) T7; // expected-error{{unknown machine mode}}
     43   typedef T __attribute__((mode(12))) T8; // expected-error{{'mode' attribute requires an identifier}}
     44 }
     45 
     46 // Check attributes on function parameters.
     47 template <class T1, class T2>
     48 void CheckParameters(T1 __attribute__((mode(SI)))   paramSI,     // expected-note2{{ignored: substitution failure}}
     49                      T1 __attribute__((mode(V4DI))) paramV4DI,   // expected-warning{{deprecated}}
     50                      T2 __attribute__((mode(SF)))   paramSF,
     51                      T2 __attribute__((mode(V4DF))) paramV4DF) { // expected-warning{{deprecated}}
     52 }
     53 
     54 
     55 // Check dependent structure.
     56 template <class T>
     57 struct TemplatedStruct {
     58   // Check fields.
     59   T __attribute__((mode(HI)))     x1;
     60   T __attribute__((mode(V4HI)))   x2;         // expected-error{{mode 'V4HI' is not supported for enumeration types}}
     61                                               // expected-warning@-1{{deprecated}}
     62 
     63   // Check typedefs.
     64   typedef T __attribute__((mode(DI)))   T1;
     65   typedef T __attribute__((mode(V8DI))) T2;   // expected-error{{mode 'V8DI' is not supported for enumeration types}}
     66                                               // expected-warning@-1{{deprecated}}
     67 
     68   // Check parameters.
     69   void f1(T __attribute__((mode(QI))) x) {}
     70   void f2(T __attribute__((mode(SF))) x) {}   // expected-error2{{type of machine mode does not match type of base type}}
     71   void f3(T __attribute__((mode(V4QI))) x) {} // expected-error{{mode 'V4QI' is not supported for enumeration types}}
     72                                               // expected-warning@-1{{deprecated}}
     73 
     74   // Check attribute on methods - it is invalid.
     75   __attribute__((mode(QI))) T g1() { return 0; } // expected-error{{'mode' attribute only applies to variables, enums, fields and typedefs}}
     76 };
     77 
     78 
     79 
     80 int main() {
     81   CheckEnumerations<int>();
     82   CheckEnumerations<EnumType>(); // expected-note{{in instantiation of}}
     83 
     84   CheckPrimitiveTypes<int>();
     85   CheckPrimitiveTypes<S>();      // expected-note{{in instantiation of}}
     86 
     87   // 'II' mode is unknown, no matter what we instantiate with.
     88   CheckMachineMode<int>();       // expected-note{{in instantiation of}}
     89   CheckMachineMode<EnumType>();  // expected-note{{in instantiation of}}
     90   CheckMachineMode<float>();     // expected-note{{in instantiation of}}
     91 
     92   int   __attribute__((mode(V4DI))) valV4DI; // expected-warning{{deprecated}}
     93   float __attribute__((mode(V4DF))) valV4DF; // expected-warning{{deprecated}}
     94   // OK.
     95   CheckParameters<int, float>(0, valV4DI, 1.0, valV4DF);
     96   // Enumeral type with vector mode is invalid.
     97   CheckParameters<EnumType, float>(0, valV4DI, 1.0, valV4DF); // expected-error{{no matching function for call}}
     98   // 'V4DF' mode with 'int' type is invalid.
     99   CheckParameters<int, int>(0, valV4DI, 1, valV4DF); // expected-error{{no matching function for call}}
    100 
    101   TemplatedStruct<int>      s1; // expected-note{{in instantiation of}}
    102   TemplatedStruct<EnumType> s2; // expected-note{{in instantiation of}}
    103   return 0;
    104 }
    105