xref: /llvm-project/clang/test/SemaOpenCL/printf-format-strings.cl (revision 5fee6936b8b241b36fadaf0dcd962e9c9adc8a69)
10ff50d49SMatt Arsenault// RUN: %clang_cc1 -cl-std=CL1.2 -cl-ext=+cl_khr_fp64 -fsyntax-only -verify %s
20ff50d49SMatt Arsenault// RUN: %clang_cc1 -cl-std=CL1.2 -cl-ext=-cl_khr_fp64 -fsyntax-only -verify %s
3e19dc613SMatt Arsenault
458fc8082SMatt Arsenaulttypedef __attribute__((ext_vector_type(4))) half half4;
558fc8082SMatt Arsenault
6e19dc613SMatt Arsenaulttypedef __attribute__((ext_vector_type(2))) float float2;
7e19dc613SMatt Arsenaulttypedef __attribute__((ext_vector_type(4))) float float4;
80ff50d49SMatt Arsenault
958fc8082SMatt Arsenault#ifdef cl_khr_fp64
1058fc8082SMatt Arsenaulttypedef __attribute__((ext_vector_type(4))) double double4;
1158fc8082SMatt Arsenault#endif
1258fc8082SMatt Arsenault
1358fc8082SMatt Arsenaulttypedef __attribute__((ext_vector_type(4))) char char4;
1458fc8082SMatt Arsenaulttypedef __attribute__((ext_vector_type(4))) unsigned char uchar4;
1558fc8082SMatt Arsenault
1658fc8082SMatt Arsenaulttypedef __attribute__((ext_vector_type(4))) short short4;
1758fc8082SMatt Arsenaulttypedef __attribute__((ext_vector_type(4))) unsigned short ushort4;
1858fc8082SMatt Arsenault
190ff50d49SMatt Arsenaulttypedef __attribute__((ext_vector_type(2))) int int2;
20e19dc613SMatt Arsenaulttypedef __attribute__((ext_vector_type(4))) int int4;
210ff50d49SMatt Arsenaulttypedef __attribute__((ext_vector_type(16))) int int16;
22e19dc613SMatt Arsenault
2358fc8082SMatt Arsenaulttypedef __attribute__((ext_vector_type(4))) long long4;
2458fc8082SMatt Arsenaulttypedef __attribute__((ext_vector_type(4))) unsigned int uint4;
2558fc8082SMatt Arsenaulttypedef __attribute__((ext_vector_type(4))) unsigned long ulong4;
2658fc8082SMatt Arsenault
27e19dc613SMatt Arsenaultint printf(__constant const char* st, ...) __attribute__((format(printf, 1, 2)));
28e19dc613SMatt Arsenault
2958fc8082SMatt Arsenault
3058fc8082SMatt Arsenault#ifdef cl_khr_fp64
3158fc8082SMatt Arsenaultkernel void format_v4f64(half4 arg_h, float4 arg_f, double4 arg_d)
3258fc8082SMatt Arsenault{
3358fc8082SMatt Arsenault  printf("%v4lf", arg_d);
3458fc8082SMatt Arsenault  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)}}
3558fc8082SMatt Arsenault  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)}}
3658fc8082SMatt Arsenault
3758fc8082SMatt Arsenault  printf("%v4lF", arg_d);
3858fc8082SMatt Arsenault  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)}}
3958fc8082SMatt Arsenault  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)}}
4058fc8082SMatt Arsenault
4158fc8082SMatt Arsenault  printf("%v4le", arg_d);
4258fc8082SMatt Arsenault  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)}}
4358fc8082SMatt Arsenault  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)}}
4458fc8082SMatt Arsenault
4558fc8082SMatt Arsenault  printf("%v4lE", arg_d);
4658fc8082SMatt Arsenault  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)}}
4758fc8082SMatt Arsenault  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)}}
4858fc8082SMatt Arsenault
4958fc8082SMatt Arsenault  printf("%v4lg", arg_d);
5058fc8082SMatt Arsenault  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)}}
5158fc8082SMatt Arsenault  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)}}
5258fc8082SMatt Arsenault
5358fc8082SMatt Arsenault  printf("%v4lG", arg_d);
5458fc8082SMatt Arsenault  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)}}
5558fc8082SMatt Arsenault  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)}}
5658fc8082SMatt Arsenault
5758fc8082SMatt Arsenault  printf("%v4la", arg_d);
5858fc8082SMatt Arsenault  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)}}
5958fc8082SMatt Arsenault  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)}}
6058fc8082SMatt Arsenault
6158fc8082SMatt Arsenault  printf("%v4lA", arg_d);
6258fc8082SMatt Arsenault  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)}}
6358fc8082SMatt Arsenault  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)}}
6458fc8082SMatt Arsenault}
6558fc8082SMatt Arsenault
6658fc8082SMatt Arsenaultkernel void format_v4f16(half4 arg_h, float4 arg_f, double4 arg_d)
6758fc8082SMatt Arsenault{
68*5fee6936SJessica Clarke  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*5fee6936SJessica Clarke  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)}}
7058fc8082SMatt Arsenault  printf("%v4hf\n", arg_h);
7158fc8082SMatt Arsenault}
7258fc8082SMatt Arsenault
7358fc8082SMatt Arsenaultkernel void no_length_modifier_scalar_fp(float f) {
7458fc8082SMatt Arsenault  printf("%hf", f); // expected-warning{{length modifier 'h' results in undefined behavior or no effect with 'f' conversion specifier}}
7558fc8082SMatt Arsenault  printf("%hlf", f); // expected-warning{{length modifier 'hl' results in undefined behavior or no effect with 'f' conversion specifier}}
7658fc8082SMatt Arsenault  printf("%lf", f); // expected-warning{{length modifier 'l' results in undefined behavior or no effect with 'f' conversion specifier}}
7758fc8082SMatt Arsenault}
7858fc8082SMatt Arsenault
7958fc8082SMatt Arsenault#endif
8058fc8082SMatt Arsenault
81e19dc613SMatt Arsenaultkernel void format_v4f32(float4 arg)
82e19dc613SMatt Arsenault{
830ff50d49SMatt Arsenault#ifdef cl_khr_fp64
84297afb14SMatt Arsenault    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)}}
850ff50d49SMatt Arsenault
860ff50d49SMatt Arsenault    // Precision modifier
87297afb14SMatt Arsenault    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)}}
880ff50d49SMatt Arsenault#else
890ff50d49SMatt Arsenault    // FIXME: These should not warn, and the type should be expected to be float.
900ff50d49SMatt Arsenault    printf("%v4f\n", arg);  // expected-warning {{double __attribute__((ext_vector_type(4)))' but the argument has type 'float4' (vector of 4 'float' values)}}
910ff50d49SMatt Arsenault
920ff50d49SMatt Arsenault    // Precision modifier
930ff50d49SMatt Arsenault    printf("%.2v4f\n", arg); // expected-warning {{double __attribute__((ext_vector_type(4)))' but the argument has type 'float4' (vector of 4 'float' values)}}
940ff50d49SMatt Arsenault#endif
950ff50d49SMatt Arsenault}
960ff50d49SMatt Arsenault
970ff50d49SMatt Arsenaultkernel void format_only_v(int arg)
980ff50d49SMatt Arsenault{
990ff50d49SMatt Arsenault    printf("%v", arg); // expected-warning {{incomplete format specifier}}
1000ff50d49SMatt Arsenault}
1010ff50d49SMatt Arsenault
1020ff50d49SMatt Arsenaultkernel void format_missing_num(int arg)
1030ff50d49SMatt Arsenault{
1040ff50d49SMatt Arsenault    printf("%v4", arg); // expected-warning {{incomplete format specifier}}
1050ff50d49SMatt Arsenault}
1060ff50d49SMatt Arsenault
1070ff50d49SMatt Arsenaultkernel void format_not_num(int arg)
1080ff50d49SMatt Arsenault{
1090ff50d49SMatt Arsenault    printf("%vNd", arg); // expected-warning {{incomplete format specifier}}
1100ff50d49SMatt Arsenault    printf("%v*d", arg); // expected-warning {{incomplete format specifier}}
1110ff50d49SMatt Arsenault}
1120ff50d49SMatt Arsenault
1130ff50d49SMatt Arsenaultkernel void format_v16i32(int16 arg)
1140ff50d49SMatt Arsenault{
1150ff50d49SMatt Arsenault    printf("%v16d\n", arg);
1160ff50d49SMatt Arsenault}
1170ff50d49SMatt Arsenault
1180ff50d49SMatt Arsenaultkernel void format_v4i32_scalar(int arg)
1190ff50d49SMatt Arsenault{
1200ff50d49SMatt Arsenault   printf("%v4d\n", arg); // expected-warning  {{format specifies type 'int __attribute__((ext_vector_type(4)))' but the argument has type 'int'}}
1210ff50d49SMatt Arsenault}
1220ff50d49SMatt Arsenault
1230ff50d49SMatt Arsenaultkernel void format_v4i32_wrong_num_elts_2_to_4(int2 arg)
1240ff50d49SMatt Arsenault{
1250ff50d49SMatt Arsenault    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)}}
1260ff50d49SMatt Arsenault}
1270ff50d49SMatt Arsenault
1280ff50d49SMatt Arsenaultkernel void format_missing_num_elts_format(int4 arg)
1290ff50d49SMatt Arsenault{
1300ff50d49SMatt Arsenault    printf("%vd\n", arg); // expected-warning {{incomplete format specifier}}
1310ff50d49SMatt Arsenault}
1320ff50d49SMatt Arsenault
1330ff50d49SMatt Arsenaultkernel void format_v4f32_scalar(float arg)
1340ff50d49SMatt Arsenault{
1350ff50d49SMatt Arsenault    printf("%v4f\n", arg); // expected-warning {{format specifies type 'double __attribute__((ext_vector_type(4)))' but the argument has type 'float'}}
136e19dc613SMatt Arsenault}
137e19dc613SMatt Arsenault
138e19dc613SMatt Arsenaultkernel void format_v4f32_wrong_num_elts(float2 arg)
139e19dc613SMatt Arsenault{
1400ff50d49SMatt Arsenault    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)}}
141e19dc613SMatt Arsenault}
142e19dc613SMatt Arsenault
143e19dc613SMatt Arsenaultkernel void format_missing_num_elts(float4 arg)
144e19dc613SMatt Arsenault{
1450ff50d49SMatt Arsenault    printf("%vf\n", arg); // expected-warning {{incomplete format specifier}}
1460ff50d49SMatt Arsenault}
1470ff50d49SMatt Arsenault
1480ff50d49SMatt Arsenaultkernel void vector_precision_modifier_v4i32_to_v4f32(int4 arg)
1490ff50d49SMatt Arsenault{
1500ff50d49SMatt Arsenault    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)}}
1510ff50d49SMatt Arsenault}
1520ff50d49SMatt Arsenault
1530ff50d49SMatt Arsenaultkernel void invalid_Y(int4 arg)
1540ff50d49SMatt Arsenault{
1550ff50d49SMatt Arsenault    printf("%v4Y\n", arg); // expected-warning {{invalid conversion specifier 'Y'}}
156e19dc613SMatt Arsenault}
157e19dc613SMatt Arsenault
158e19dc613SMatt Arsenault// FIXME: This should warn
1590ff50d49SMatt Arsenaultkernel void crash_on_s(int4 arg)
160e19dc613SMatt Arsenault{
1610ff50d49SMatt Arsenault    printf("%v4s\n", arg);
162e19dc613SMatt Arsenault}
16358fc8082SMatt Arsenault
16458fc8082SMatt Arsenault
16558fc8082SMatt Arsenaultkernel 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) {
16658fc8082SMatt Arsenault  printf("%v4hhd", arg_c);
16758fc8082SMatt Arsenault  printf("%v4hhd", arg_s);
16858fc8082SMatt Arsenault  printf("%v4hhd", arg_i);
16958fc8082SMatt Arsenault  printf("%v4hhd", arg_l);
17058fc8082SMatt Arsenault
17158fc8082SMatt Arsenault  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)}}
17258fc8082SMatt Arsenault  printf("%v4hd", arg_s);
17358fc8082SMatt Arsenault  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)}}
17458fc8082SMatt Arsenault  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)}}
17558fc8082SMatt Arsenault
17658fc8082SMatt Arsenault  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)}}
17758fc8082SMatt Arsenault  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)}}
17858fc8082SMatt Arsenault  printf("%v4hld", arg_i);
17958fc8082SMatt Arsenault  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)}}
18058fc8082SMatt Arsenault
18158fc8082SMatt Arsenault  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)}}
18258fc8082SMatt Arsenault  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)}}
18358fc8082SMatt Arsenault  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)}}
18458fc8082SMatt Arsenault  printf("%v4ld", arg_l);
18558fc8082SMatt Arsenault
18658fc8082SMatt Arsenault
18758fc8082SMatt Arsenault
18858fc8082SMatt Arsenault  printf("%v4hhu", arg_uc);
18958fc8082SMatt Arsenault  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)}}
19058fc8082SMatt Arsenault  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)}}
19158fc8082SMatt Arsenault  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)}}
19258fc8082SMatt Arsenault
19358fc8082SMatt Arsenault  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)}}
19458fc8082SMatt Arsenault  printf("%v4hu", arg_us);
19558fc8082SMatt Arsenault  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)}}
19658fc8082SMatt Arsenault  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)}}
19758fc8082SMatt Arsenault
19858fc8082SMatt Arsenault  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)}}
19958fc8082SMatt Arsenault  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)}}
20058fc8082SMatt Arsenault  printf("%v4hlu", arg_ui);
20158fc8082SMatt Arsenault  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)}}
20258fc8082SMatt Arsenault
20358fc8082SMatt Arsenault  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)}}
20458fc8082SMatt Arsenault  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)}}
20558fc8082SMatt Arsenault  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)}}
20658fc8082SMatt Arsenault  printf("%v4lu", arg_ul);
20758fc8082SMatt Arsenault
20858fc8082SMatt Arsenault
20958fc8082SMatt Arsenault  printf("%v4n", &arg_i); // expected-warning{{invalid conversion specifier 'n'}}
21058fc8082SMatt Arsenault  printf("%v4hln", &arg_i); // expected-warning{{invalid conversion specifier 'n'}}
21158fc8082SMatt Arsenault}
212