[clang] Handle __declspec() attributes in using
[llvm-project.git] / clang / test / SemaOpenCL / printf-format-strings.cl
blob6cdfc7e60b37963f2d146b60f32407f4061f961b
1 // RUN: %clang_cc1 -cl-std=CL1.2 -cl-ext=+cl_khr_fp64 -fsyntax-only -verify %s
2 // RUN: %clang_cc1 -cl-std=CL1.2 -cl-ext=-cl_khr_fp64 -fsyntax-only -verify %s
4 typedef __attribute__((ext_vector_type(4))) half half4;
6 typedef __attribute__((ext_vector_type(2))) float float2;
7 typedef __attribute__((ext_vector_type(4))) float float4;
9 #ifdef cl_khr_fp64
10 typedef __attribute__((ext_vector_type(4))) double double4;
11 #endif
13 typedef __attribute__((ext_vector_type(4))) char char4;
14 typedef __attribute__((ext_vector_type(4))) unsigned char uchar4;
16 typedef __attribute__((ext_vector_type(4))) short short4;
17 typedef __attribute__((ext_vector_type(4))) unsigned short ushort4;
19 typedef __attribute__((ext_vector_type(2))) int int2;
20 typedef __attribute__((ext_vector_type(4))) int int4;
21 typedef __attribute__((ext_vector_type(16))) int int16;
23 typedef __attribute__((ext_vector_type(4))) long long4;
24 typedef __attribute__((ext_vector_type(4))) unsigned int uint4;
25 typedef __attribute__((ext_vector_type(4))) unsigned long ulong4;
27 int printf(__constant const char* st, ...) __attribute__((format(printf, 1, 2)));
30 #ifdef cl_khr_fp64
31 kernel void format_v4f64(half4 arg_h, float4 arg_f, double4 arg_d)
33 printf("%v4lf", arg_d);
34 printf("%v4lf", arg_f); // expected-warning{{format specifies type 'double __attribute__((ext_vector_type(4)))' but the argument has type 'float4' (vector of 4 'float' values)}}
35 printf("%v4lf", arg_h); // expected-warning{{format specifies type 'double __attribute__((ext_vector_type(4)))' but the argument has type 'half4' (vector of 4 'half' values)}}
37 printf("%v4lF", arg_d);
38 printf("%v4lF", arg_f); // expected-warning{{format specifies type 'double __attribute__((ext_vector_type(4)))' but the argument has type 'float4' (vector of 4 'float' values)}}
39 printf("%v4lF", arg_h); // expected-warning{{format specifies type 'double __attribute__((ext_vector_type(4)))' but the argument has type 'half4' (vector of 4 'half' values)}}
41 printf("%v4le", arg_d);
42 printf("%v4le", arg_f); // expected-warning{{format specifies type 'double __attribute__((ext_vector_type(4)))' but the argument has type 'float4' (vector of 4 'float' values)}}
43 printf("%v4le", arg_h); // expected-warning{{format specifies type 'double __attribute__((ext_vector_type(4)))' but the argument has type 'half4' (vector of 4 'half' values)}}
45 printf("%v4lE", arg_d);
46 printf("%v4lE", arg_f); // expected-warning{{format specifies type 'double __attribute__((ext_vector_type(4)))' but the argument has type 'float4' (vector of 4 'float' values)}}
47 printf("%v4lE", arg_h); // expected-warning{{format specifies type 'double __attribute__((ext_vector_type(4)))' but the argument has type 'half4' (vector of 4 'half' values)}}
49 printf("%v4lg", arg_d);
50 printf("%v4lg", arg_f); // expected-warning{{format specifies type 'double __attribute__((ext_vector_type(4)))' but the argument has type 'float4' (vector of 4 'float' values)}}
51 printf("%v4lg", arg_h); // expected-warning{{format specifies type 'double __attribute__((ext_vector_type(4)))' but the argument has type 'half4' (vector of 4 'half' values)}}
53 printf("%v4lG", arg_d);
54 printf("%v4lG", arg_f); // expected-warning{{format specifies type 'double __attribute__((ext_vector_type(4)))' but the argument has type 'float4' (vector of 4 'float' values)}}
55 printf("%v4lG", arg_h); // expected-warning{{format specifies type 'double __attribute__((ext_vector_type(4)))' but the argument has type 'half4' (vector of 4 'half' values)}}
57 printf("%v4la", arg_d);
58 printf("%v4la", arg_f); // expected-warning{{format specifies type 'double __attribute__((ext_vector_type(4)))' but the argument has type 'float4' (vector of 4 'float' values)}}
59 printf("%v4la", arg_h); // expected-warning{{format specifies type 'double __attribute__((ext_vector_type(4)))' but the argument has type 'half4' (vector of 4 'half' values)}}
61 printf("%v4lA", arg_d);
62 printf("%v4lA", arg_f); // expected-warning{{format specifies type 'double __attribute__((ext_vector_type(4)))' but the argument has type 'float4' (vector of 4 'float' values)}}
63 printf("%v4lA", arg_h); // expected-warning{{format specifies type 'double __attribute__((ext_vector_type(4)))' but the argument has type 'half4' (vector of 4 'half' values)}}
66 kernel void format_v4f16(half4 arg_h, float4 arg_f, double4 arg_d)
68 printf("%v4hf\n", arg_d); // expected-warning{{format specifies type 'half __attribute__((ext_vector_type(4)))' but the argument has type 'double4' (vector of 4 'double' values)}}
69 printf("%v4hf\n", arg_f); // expected-warning{{format specifies type 'half __attribute__((ext_vector_type(4)))' but the argument has type 'float4' (vector of 4 'float' values)}}
70 printf("%v4hf\n", arg_h);
73 kernel void no_length_modifier_scalar_fp(float f) {
74 printf("%hf", f); // expected-warning{{length modifier 'h' results in undefined behavior or no effect with 'f' conversion specifier}}
75 printf("%hlf", f); // expected-warning{{length modifier 'hl' results in undefined behavior or no effect with 'f' conversion specifier}}
76 printf("%lf", f); // expected-warning{{length modifier 'l' results in undefined behavior or no effect with 'f' conversion specifier}}
79 #endif
81 kernel void format_v4f32(float4 arg)
83 #ifdef cl_khr_fp64
84 printf("%v4f\n", arg); // expected-warning{{format specifies type 'double __attribute__((ext_vector_type(4)))' but the argument has type 'float4' (vector of 4 'float' values)}}
86 // Precision modifier
87 printf("%.2v4f\n", arg); //expected-warning{{format specifies type 'double __attribute__((ext_vector_type(4)))' but the argument has type 'float4' (vector of 4 'float' values)}}
88 #else
89 // FIXME: These should not warn, and the type should be expected to be float.
90 printf("%v4f\n", arg); // expected-warning {{double __attribute__((ext_vector_type(4)))' but the argument has type 'float4' (vector of 4 'float' values)}}
92 // Precision modifier
93 printf("%.2v4f\n", arg); // expected-warning {{double __attribute__((ext_vector_type(4)))' but the argument has type 'float4' (vector of 4 'float' values)}}
94 #endif
97 kernel void format_only_v(int arg)
99 printf("%v", arg); // expected-warning {{incomplete format specifier}}
102 kernel void format_missing_num(int arg)
104 printf("%v4", arg); // expected-warning {{incomplete format specifier}}
107 kernel void format_not_num(int arg)
109 printf("%vNd", arg); // expected-warning {{incomplete format specifier}}
110 printf("%v*d", arg); // expected-warning {{incomplete format specifier}}
113 kernel void format_v16i32(int16 arg)
115 printf("%v16d\n", arg);
118 kernel void format_v4i32_scalar(int arg)
120 printf("%v4d\n", arg); // expected-warning {{format specifies type 'int __attribute__((ext_vector_type(4)))' but the argument has type 'int'}}
123 kernel void format_v4i32_wrong_num_elts_2_to_4(int2 arg)
125 printf("%v4d\n", arg); // expected-warning {{format specifies type 'int __attribute__((ext_vector_type(4)))' but the argument has type 'int2' (vector of 2 'int' values)}}
128 kernel void format_missing_num_elts_format(int4 arg)
130 printf("%vd\n", arg); // expected-warning {{incomplete format specifier}}
133 kernel void format_v4f32_scalar(float arg)
135 printf("%v4f\n", arg); // expected-warning {{format specifies type 'double __attribute__((ext_vector_type(4)))' but the argument has type 'float'}}
138 kernel void format_v4f32_wrong_num_elts(float2 arg)
140 printf("%v4f\n", arg); // expected-warning {{format specifies type 'double __attribute__((ext_vector_type(4)))' but the argument has type 'float2' (vector of 2 'float' values)}}
143 kernel void format_missing_num_elts(float4 arg)
145 printf("%vf\n", arg); // expected-warning {{incomplete format specifier}}
148 kernel void vector_precision_modifier_v4i32_to_v4f32(int4 arg)
150 printf("%.2v4f\n", arg); // expected-warning {{format specifies type 'double __attribute__((ext_vector_type(4)))' but the argument has type 'int4' (vector of 4 'int' values)}}
153 kernel void invalid_Y(int4 arg)
155 printf("%v4Y\n", arg); // expected-warning {{invalid conversion specifier 'Y'}}
158 // FIXME: This should warn
159 kernel void crash_on_s(int4 arg)
161 printf("%v4s\n", arg);
165 kernel void printf_int_length_modifiers(char4 arg_c, short4 arg_s, int4 arg_i, long4 arg_l, uchar4 arg_uc, ushort4 arg_us, uint4 arg_ui, ulong4 arg_ul) {
166 printf("%v4hhd", arg_c);
167 printf("%v4hhd", arg_s);
168 printf("%v4hhd", arg_i);
169 printf("%v4hhd", arg_l);
171 printf("%v4hd", arg_c); // expected-warning{{format specifies type 'short __attribute__((ext_vector_type(4)))' but the argument has type 'char4' (vector of 4 'char' values)}}
172 printf("%v4hd", arg_s);
173 printf("%v4hd", arg_i); // expected-warning{{format specifies type 'short __attribute__((ext_vector_type(4)))' but the argument has type 'int4' (vector of 4 'int' values)}}
174 printf("%v4hd", arg_l); // expected-warning{{format specifies type 'short __attribute__((ext_vector_type(4)))' but the argument has type 'long4' (vector of 4 'long' values)}}
176 printf("%v4hld", arg_c); // expected-warning{{format specifies type 'int __attribute__((ext_vector_type(4)))' but the argument has type 'char4' (vector of 4 'char' values)}}
177 printf("%v4hld", arg_s); // expected-warning{{format specifies type 'int __attribute__((ext_vector_type(4)))' but the argument has type 'short4' (vector of 4 'short' values)}}
178 printf("%v4hld", arg_i);
179 printf("%v4hld", arg_l); // expected-warning{{format specifies type 'int __attribute__((ext_vector_type(4)))' but the argument has type 'long4' (vector of 4 'long' values)}}
181 printf("%v4ld", arg_c); // expected-warning{{format specifies type 'long __attribute__((ext_vector_type(4)))' but the argument has type 'char4' (vector of 4 'char' values)}}
182 printf("%v4ld", arg_s); // expected-warning{{format specifies type 'long __attribute__((ext_vector_type(4)))' but the argument has type 'short4' (vector of 4 'short' values)}}
183 printf("%v4ld", arg_i); // expected-warning{{format specifies type 'long __attribute__((ext_vector_type(4)))' but the argument has type 'int4' (vector of 4 'int' values)}}
184 printf("%v4ld", arg_l);
188 printf("%v4hhu", arg_uc);
189 printf("%v4hhu", arg_us); // expected-warning{{format specifies type 'unsigned char __attribute__((ext_vector_type(4)))' but the argument has type 'ushort4' (vector of 4 'unsigned short' values)}}
190 printf("%v4hhu", arg_ui); // expected-warning{{format specifies type 'unsigned char __attribute__((ext_vector_type(4)))' but the argument has type 'uint4' (vector of 4 'unsigned int' values)}}
191 printf("%v4hhu", arg_ul); // expected-warning{{format specifies type 'unsigned char __attribute__((ext_vector_type(4)))' but the argument has type 'ulong4' (vector of 4 'unsigned long' values)}}
193 printf("%v4hu", arg_uc); // expected-warning{{format specifies type 'unsigned short __attribute__((ext_vector_type(4)))' but the argument has type 'uchar4' (vector of 4 'unsigned char' values)}}
194 printf("%v4hu", arg_us);
195 printf("%v4hu", arg_ui); // expected-warning{{format specifies type 'unsigned short __attribute__((ext_vector_type(4)))' but the argument has type 'uint4' (vector of 4 'unsigned int' values)}}
196 printf("%v4hu", arg_ul); // expected-warning{{format specifies type 'unsigned short __attribute__((ext_vector_type(4)))' but the argument has type 'ulong4' (vector of 4 'unsigned long' values)}}
198 printf("%v4hlu", arg_uc); // expected-warning{{format specifies type 'unsigned int __attribute__((ext_vector_type(4)))' but the argument has type 'uchar4' (vector of 4 'unsigned char' values)}}
199 printf("%v4hlu", arg_us); // expected-warning{{format specifies type 'unsigned int __attribute__((ext_vector_type(4)))' but the argument has type 'ushort4' (vector of 4 'unsigned short' values)}}
200 printf("%v4hlu", arg_ui);
201 printf("%v4hlu", arg_ul); // expected-warning{{format specifies type 'unsigned int __attribute__((ext_vector_type(4)))' but the argument has type 'ulong4' (vector of 4 'unsigned long' values)}}
203 printf("%v4lu", arg_uc); // expected-warning{{format specifies type 'unsigned long __attribute__((ext_vector_type(4)))' but the argument has type 'uchar4' (vector of 4 'unsigned char' values)}}
204 printf("%v4lu", arg_us); // expected-warning{{format specifies type 'unsigned long __attribute__((ext_vector_type(4)))' but the argument has type 'ushort4' (vector of 4 'unsigned short' values)}}
205 printf("%v4lu", arg_ui); // expected-warning{{format specifies type 'unsigned long __attribute__((ext_vector_type(4)))' but the argument has type 'uint4' (vector of 4 'unsigned int' values)}}
206 printf("%v4lu", arg_ul);
209 printf("%v4n", &arg_i); // expected-warning{{invalid conversion specifier 'n'}}
210 printf("%v4hln", &arg_i); // expected-warning{{invalid conversion specifier 'n'}}