printf-format-strings.cl 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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
  3. typedef __attribute__((ext_vector_type(4))) half half4;
  4. typedef __attribute__((ext_vector_type(2))) float float2;
  5. typedef __attribute__((ext_vector_type(4))) float float4;
  6. #ifdef cl_khr_fp64
  7. typedef __attribute__((ext_vector_type(4))) double double4;
  8. #endif
  9. typedef __attribute__((ext_vector_type(4))) char char4;
  10. typedef __attribute__((ext_vector_type(4))) unsigned char uchar4;
  11. typedef __attribute__((ext_vector_type(4))) short short4;
  12. typedef __attribute__((ext_vector_type(4))) unsigned short ushort4;
  13. typedef __attribute__((ext_vector_type(2))) int int2;
  14. typedef __attribute__((ext_vector_type(4))) int int4;
  15. typedef __attribute__((ext_vector_type(16))) int int16;
  16. typedef __attribute__((ext_vector_type(4))) long long4;
  17. typedef __attribute__((ext_vector_type(4))) unsigned int uint4;
  18. typedef __attribute__((ext_vector_type(4))) unsigned long ulong4;
  19. int printf(__constant const char* st, ...) __attribute__((format(printf, 1, 2)));
  20. #ifdef cl_khr_fp64
  21. kernel void format_v4f64(half4 arg_h, float4 arg_f, double4 arg_d)
  22. {
  23. printf("%v4lf", arg_d);
  24. 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)}}
  25. 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)}}
  26. printf("%v4lF", arg_d);
  27. 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)}}
  28. 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)}}
  29. printf("%v4le", arg_d);
  30. 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)}}
  31. 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)}}
  32. printf("%v4lE", arg_d);
  33. 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)}}
  34. 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)}}
  35. printf("%v4lg", arg_d);
  36. 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)}}
  37. 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)}}
  38. printf("%v4lG", arg_d);
  39. 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)}}
  40. 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)}}
  41. printf("%v4la", arg_d);
  42. 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)}}
  43. 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)}}
  44. printf("%v4lA", arg_d);
  45. 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)}}
  46. 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)}}
  47. }
  48. kernel void format_v4f16(half4 arg_h, float4 arg_f, double4 arg_d)
  49. {
  50. printf("%v4hf\n", arg_d); // expected-warning{{format specifies type '__fp16 __attribute__((ext_vector_type(4)))' but the argument has type 'double4' (vector of 4 'double' values)}}
  51. printf("%v4hf\n", arg_f); // expected-warning{{format specifies type '__fp16 __attribute__((ext_vector_type(4)))' but the argument has type 'float4' (vector of 4 'float' values)}}
  52. printf("%v4hf\n", arg_h);
  53. }
  54. kernel void no_length_modifier_scalar_fp(float f) {
  55. printf("%hf", f); // expected-warning{{length modifier 'h' results in undefined behavior or no effect with 'f' conversion specifier}}
  56. printf("%hlf", f); // expected-warning{{length modifier 'hl' results in undefined behavior or no effect with 'f' conversion specifier}}
  57. printf("%lf", f); // expected-warning{{length modifier 'l' results in undefined behavior or no effect with 'f' conversion specifier}}
  58. }
  59. #endif
  60. kernel void format_v4f32(float4 arg)
  61. {
  62. #ifdef cl_khr_fp64
  63. 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)}}
  64. // Precision modifier
  65. 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)}}
  66. #else
  67. // FIXME: These should not warn, and the type should be expected to be float.
  68. printf("%v4f\n", arg); // expected-warning {{double __attribute__((ext_vector_type(4)))' but the argument has type 'float4' (vector of 4 'float' values)}}
  69. // Precision modifier
  70. printf("%.2v4f\n", arg); // expected-warning {{double __attribute__((ext_vector_type(4)))' but the argument has type 'float4' (vector of 4 'float' values)}}
  71. #endif
  72. }
  73. kernel void format_only_v(int arg)
  74. {
  75. printf("%v", arg); // expected-warning {{incomplete format specifier}}
  76. }
  77. kernel void format_missing_num(int arg)
  78. {
  79. printf("%v4", arg); // expected-warning {{incomplete format specifier}}
  80. }
  81. kernel void format_not_num(int arg)
  82. {
  83. printf("%vNd", arg); // expected-warning {{incomplete format specifier}}
  84. printf("%v*d", arg); // expected-warning {{incomplete format specifier}}
  85. }
  86. kernel void format_v16i32(int16 arg)
  87. {
  88. printf("%v16d\n", arg);
  89. }
  90. kernel void format_v4i32_scalar(int arg)
  91. {
  92. printf("%v4d\n", arg); // expected-warning {{format specifies type 'int __attribute__((ext_vector_type(4)))' but the argument has type 'int'}}
  93. }
  94. kernel void format_v4i32_wrong_num_elts_2_to_4(int2 arg)
  95. {
  96. 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)}}
  97. }
  98. kernel void format_missing_num_elts_format(int4 arg)
  99. {
  100. printf("%vd\n", arg); // expected-warning {{incomplete format specifier}}
  101. }
  102. kernel void format_v4f32_scalar(float arg)
  103. {
  104. printf("%v4f\n", arg); // expected-warning {{format specifies type 'double __attribute__((ext_vector_type(4)))' but the argument has type 'float'}}
  105. }
  106. kernel void format_v4f32_wrong_num_elts(float2 arg)
  107. {
  108. 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)}}
  109. }
  110. kernel void format_missing_num_elts(float4 arg)
  111. {
  112. printf("%vf\n", arg); // expected-warning {{incomplete format specifier}}
  113. }
  114. kernel void vector_precision_modifier_v4i32_to_v4f32(int4 arg)
  115. {
  116. 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)}}
  117. }
  118. kernel void invalid_Y(int4 arg)
  119. {
  120. printf("%v4Y\n", arg); // expected-warning {{invalid conversion specifier 'Y'}}
  121. }
  122. // FIXME: This should warn
  123. kernel void crash_on_s(int4 arg)
  124. {
  125. printf("%v4s\n", arg);
  126. }
  127. 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) {
  128. printf("%v4hhd", arg_c);
  129. printf("%v4hhd", arg_s);
  130. printf("%v4hhd", arg_i);
  131. printf("%v4hhd", arg_l);
  132. 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)}}
  133. printf("%v4hd", arg_s);
  134. 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)}}
  135. 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)}}
  136. 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)}}
  137. 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)}}
  138. printf("%v4hld", arg_i);
  139. 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)}}
  140. 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)}}
  141. 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)}}
  142. 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)}}
  143. printf("%v4ld", arg_l);
  144. printf("%v4hhu", arg_uc);
  145. 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)}}
  146. 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)}}
  147. 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)}}
  148. 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)}}
  149. printf("%v4hu", arg_us);
  150. 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)}}
  151. 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)}}
  152. 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)}}
  153. 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)}}
  154. printf("%v4hlu", arg_ui);
  155. 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)}}
  156. 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)}}
  157. 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)}}
  158. 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)}}
  159. printf("%v4lu", arg_ul);
  160. printf("%v4n", &arg_i); // expected-warning{{invalid conversion specifier 'n'}}
  161. printf("%v4hln", &arg_i); // expected-warning{{invalid conversion specifier 'n'}}
  162. }