summaryrefslogtreecommitdiffstats
path: root/clang/test
diff options
context:
space:
mode:
Diffstat (limited to 'clang/test')
-rw-r--r--clang/test/Sema/format-strings.c2
-rw-r--r--clang/test/SemaOpenCL/format-strings-fixit.cl58
-rw-r--r--clang/test/SemaOpenCL/printf-format-string-warnings.cl10
-rw-r--r--clang/test/SemaOpenCL/printf-format-strings.cl119
4 files changed, 178 insertions, 11 deletions
diff --git a/clang/test/Sema/format-strings.c b/clang/test/Sema/format-strings.c
index a9af8ce5dee..e8acd40c8d2 100644
--- a/clang/test/Sema/format-strings.c
+++ b/clang/test/Sema/format-strings.c
@@ -617,6 +617,8 @@ void test_opencl_vector_format(int x) {
printf("%v4d", x); // expected-warning{{invalid conversion specifier 'v'}}
printf("%vd", x); // expected-warning{{invalid conversion specifier 'v'}}
printf("%0vd", x); // expected-warning{{invalid conversion specifier 'v'}}
+ printf("%hlf", x); // expected-warning{{invalid conversion specifier 'l'}}
+ printf("%hld", x); // expected-warning{{invalid conversion specifier 'l'}}
}
// Test that we correctly merge the format in both orders.
diff --git a/clang/test/SemaOpenCL/format-strings-fixit.cl b/clang/test/SemaOpenCL/format-strings-fixit.cl
index b9f949ffe2f..e1181e1e3e6 100644
--- a/clang/test/SemaOpenCL/format-strings-fixit.cl
+++ b/clang/test/SemaOpenCL/format-strings-fixit.cl
@@ -3,22 +3,72 @@
// RUN: %clang_cc1 -cl-std=CL1.2 -fsyntax-only -pedantic -Wall -Werror %t
// RUN: %clang_cc1 -cl-std=CL1.2 -E -o - %t | FileCheck %s
+typedef __attribute__((ext_vector_type(4))) char char4;
+typedef __attribute__((ext_vector_type(4))) short short4;
typedef __attribute__((ext_vector_type(4))) int int4;
+typedef __attribute__((ext_vector_type(4))) unsigned int uint4;
typedef __attribute__((ext_vector_type(8))) int int8;
+typedef __attribute__((ext_vector_type(4))) long long4;
+typedef __attribute__((ext_vector_type(4))) float float4;
+typedef __attribute__((ext_vector_type(4))) double double4;
int printf(__constant const char* st, ...) __attribute__((format(printf, 1, 2)));
void vector_fixits() {
printf("%v4f", (int4) 123);
- // CHECK: printf("%v4d", (int4) 123);
+ // CHECK: printf("%v4hld", (int4) 123);
printf("%v8d", (int4) 123);
- // CHECK: printf("%v4d", (int4) 123);
+ // CHECK: printf("%v4hld", (int4) 123);
printf("%v4d", (int8) 123);
- // CHECK: printf("%v8d", (int8) 123);
+ // CHECK: printf("%v8hld", (int8) 123);
printf("%v4f", (int8) 123);
- // CHECK: printf("%v8d", (int8) 123);
+ // CHECK: printf("%v8hld", (int8) 123);
+
+ printf("%v4ld", (int8) 123);
+ // CHECK: printf("%v8hld", (int8) 123);
+
+ printf("%v4hlf", (int4) 123);
+ // CHECK: printf("%v4hld", (int4) 123);
+
+ printf("%v8hld", (int4) 123);
+ // CHECK: printf("%v4hld", (int4) 123);
+
+ printf("%v4hld", (int8) 123);
+ // CHECK: printf("%v8hld", (int8) 123);
+
+ printf("%v4hlf", (int8) 123);
+ // CHECK: printf("%v8hld", (int8) 123);
+
+ printf("%v4hd", (int4) 123);
+ // CHECK: printf("%v4hld", (int4) 123);
+
+ printf("%v4hld", (short4) 123);
+ // CHECK: printf("%v4hd", (short4) 123);
+
+ printf("%v4ld", (short4) 123);
+ // CHECK: printf("%v4hd", (short4) 123);
+
+ printf("%v4hld", (long4) 123);
+ // CHECK: printf("%v4ld", (long4) 123);
+
+ printf("%v8f", (float4) 2.0f);
+ // CHECK: printf("%v4hlf", (float4) 2.0f);
+
+ printf("%v4f", (float4) 2.0f);
+ // CHECK: printf("%v4hlf", (float4) 2.0f);
+
+ printf("%v4lf", (double4) 2.0);
+ // CHECK: printf("%v4lf", (double4) 2.0);
+
+ /// FIXME: This should be fixed
+ printf("%v4hhd", (int4) 123);
+ // CHECK: printf("%v4hhd", (int4) 123);
+
+ /// FIXME: This should be fixed
+ printf("%v4hhd", (int8) 123);
+ // CHECK: printf("%v4hhd", (int8) 123);
}
diff --git a/clang/test/SemaOpenCL/printf-format-string-warnings.cl b/clang/test/SemaOpenCL/printf-format-string-warnings.cl
index 39b85940270..d08c95b6d8a 100644
--- a/clang/test/SemaOpenCL/printf-format-string-warnings.cl
+++ b/clang/test/SemaOpenCL/printf-format-string-warnings.cl
@@ -1,14 +1,12 @@
// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL2.0 -finclude-default-header
-// FIXME: Make sure warnings are produced based on printf format strings.
-
-// expected-no-diagnostics
+// Make sure warnings are produced based on printf format strings.
kernel void format_string_warnings(__constant char* arg) {
- printf("%d", arg);
+ printf("%d", arg); // expected-warning {{format specifies type 'int' but the argument has type '__constant char *'}}
- printf("not enough arguments %d %d", 4);
+ printf("not enough arguments %d %d", 4); // expected-warning {{more '%' conversions than data arguments}}
- printf("too many arguments", 4);
+ printf("too many arguments", 4); // expected-warning {{data argument not used by format string}}
}
diff --git a/clang/test/SemaOpenCL/printf-format-strings.cl b/clang/test/SemaOpenCL/printf-format-strings.cl
index 212e1f8981c..0cfeeb13579 100644
--- a/clang/test/SemaOpenCL/printf-format-strings.cl
+++ b/clang/test/SemaOpenCL/printf-format-strings.cl
@@ -1,22 +1,90 @@
// RUN: %clang_cc1 -cl-std=CL1.2 -cl-ext=+cl_khr_fp64 -fsyntax-only -verify %s
// RUN: %clang_cc1 -cl-std=CL1.2 -cl-ext=-cl_khr_fp64 -fsyntax-only -verify %s
+typedef __attribute__((ext_vector_type(4))) half half4;
+
typedef __attribute__((ext_vector_type(2))) float float2;
typedef __attribute__((ext_vector_type(4))) float float4;
+#ifdef cl_khr_fp64
+typedef __attribute__((ext_vector_type(4))) double double4;
+#endif
+
+typedef __attribute__((ext_vector_type(4))) char char4;
+typedef __attribute__((ext_vector_type(4))) unsigned char uchar4;
+
+typedef __attribute__((ext_vector_type(4))) short short4;
+typedef __attribute__((ext_vector_type(4))) unsigned short ushort4;
+
typedef __attribute__((ext_vector_type(2))) int int2;
typedef __attribute__((ext_vector_type(4))) int int4;
typedef __attribute__((ext_vector_type(16))) int int16;
+typedef __attribute__((ext_vector_type(4))) long long4;
+typedef __attribute__((ext_vector_type(4))) unsigned int uint4;
+typedef __attribute__((ext_vector_type(4))) unsigned long ulong4;
+
int printf(__constant const char* st, ...) __attribute__((format(printf, 1, 2)));
+
+#ifdef cl_khr_fp64
+kernel void format_v4f64(half4 arg_h, float4 arg_f, double4 arg_d)
+{
+ printf("%v4lf", arg_d);
+ 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)}}
+ 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)}}
+
+ printf("%v4lF", arg_d);
+ 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)}}
+ 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)}}
+
+ printf("%v4le", arg_d);
+ 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)}}
+ 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)}}
+
+ printf("%v4lE", arg_d);
+ 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)}}
+ 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)}}
+
+ printf("%v4lg", arg_d);
+ 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)}}
+ 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)}}
+
+ printf("%v4lG", arg_d);
+ 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)}}
+ 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)}}
+
+ printf("%v4la", arg_d);
+ 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)}}
+ 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)}}
+
+ printf("%v4lA", arg_d);
+ 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)}}
+ 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)}}
+}
+
+kernel void format_v4f16(half4 arg_h, float4 arg_f, double4 arg_d)
+{
+ 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)}}
+ 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)}}
+ printf("%v4hf\n", arg_h);
+}
+
+kernel void no_length_modifier_scalar_fp(float f) {
+ printf("%hf", f); // expected-warning{{length modifier 'h' results in undefined behavior or no effect with 'f' conversion specifier}}
+ printf("%hlf", f); // expected-warning{{length modifier 'hl' results in undefined behavior or no effect with 'f' conversion specifier}}
+ printf("%lf", f); // expected-warning{{length modifier 'l' results in undefined behavior or no effect with 'f' conversion specifier}}
+}
+
+#endif
+
kernel void format_v4f32(float4 arg)
{
#ifdef cl_khr_fp64
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)}}
// Precision modifier
- 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)}}
+ 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)}}
#else
// FIXME: These should not warn, and the type should be expected to be float.
printf("%v4f\n", arg); // expected-warning {{double __attribute__((ext_vector_type(4)))' but the argument has type 'float4' (vector of 4 'float' values)}}
@@ -92,3 +160,52 @@ kernel void crash_on_s(int4 arg)
{
printf("%v4s\n", arg);
}
+
+
+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) {
+ printf("%v4hhd", arg_c);
+ printf("%v4hhd", arg_s);
+ printf("%v4hhd", arg_i);
+ printf("%v4hhd", arg_l);
+
+ 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)}}
+ printf("%v4hd", arg_s);
+ 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)}}
+ 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)}}
+
+ 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)}}
+ 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)}}
+ printf("%v4hld", arg_i);
+ 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)}}
+
+ 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)}}
+ 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)}}
+ 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)}}
+ printf("%v4ld", arg_l);
+
+
+
+ printf("%v4hhu", arg_uc);
+ 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)}}
+ 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)}}
+ 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)}}
+
+ 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)}}
+ printf("%v4hu", arg_us);
+ 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)}}
+ 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)}}
+
+ 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)}}
+ 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)}}
+ printf("%v4hlu", arg_ui);
+ 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)}}
+
+ 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)}}
+ 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)}}
+ 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)}}
+ printf("%v4lu", arg_ul);
+
+
+ printf("%v4n", &arg_i); // expected-warning{{invalid conversion specifier 'n'}}
+ printf("%v4hln", &arg_i); // expected-warning{{invalid conversion specifier 'n'}}
+}
OpenPOWER on IntegriCloud