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