diff options
author | Matt Arsenault <Matthew.Arsenault@amd.com> | 2018-12-01 22:16:27 +0000 |
---|---|---|
committer | Matt Arsenault <Matthew.Arsenault@amd.com> | 2018-12-01 22:16:27 +0000 |
commit | 938b65e725c6e0a48111f45c8378b575790c9184 (patch) | |
tree | aac3a60dc65e9518286dc10440aa847963e1d0d7 /test/SemaOpenCL | |
parent | 7a6f35c7122ec13f0b63e7cba004b8cee5bc274e (diff) | |
download | clang-938b65e725c6e0a48111f45c8378b575790c9184.tar.gz |
OpenCL: Improve vector printf warnings
The vector modifier is considered separate, so
don't treat it as a conversion specifier.
This is still not warning on some cases, like
using a type that isn't a valid vector element.
Fixes bug 39652
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@348084 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/SemaOpenCL')
-rw-r--r-- | test/SemaOpenCL/format-strings-fixit.cl | 24 | ||||
-rw-r--r-- | test/SemaOpenCL/printf-format-strings.cl | 80 |
2 files changed, 94 insertions, 10 deletions
diff --git a/test/SemaOpenCL/format-strings-fixit.cl b/test/SemaOpenCL/format-strings-fixit.cl new file mode 100644 index 0000000000..b9f949ffe2 --- /dev/null +++ b/test/SemaOpenCL/format-strings-fixit.cl @@ -0,0 +1,24 @@ +// RUN: cp %s %t +// RUN: %clang_cc1 -cl-std=CL1.2 -pedantic -Wall -fixit %t +// 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))) int int4; +typedef __attribute__((ext_vector_type(8))) int int8; + +int printf(__constant const char* st, ...) __attribute__((format(printf, 1, 2))); + + +void vector_fixits() { + printf("%v4f", (int4) 123); + // CHECK: printf("%v4d", (int4) 123); + + printf("%v8d", (int4) 123); + // CHECK: printf("%v4d", (int4) 123); + + printf("%v4d", (int8) 123); + // CHECK: printf("%v8d", (int8) 123); + + printf("%v4f", (int8) 123); + // CHECK: printf("%v8d", (int8) 123); +} diff --git a/test/SemaOpenCL/printf-format-strings.cl b/test/SemaOpenCL/printf-format-strings.cl index d5748e18ed..079a834956 100644 --- a/test/SemaOpenCL/printf-format-strings.cl +++ b/test/SemaOpenCL/printf-format-strings.cl @@ -1,34 +1,94 @@ -// RUN: %clang_cc1 -cl-std=CL1.2 -fsyntax-only -verify %s +// 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(2))) float float2; typedef __attribute__((ext_vector_type(4))) float float4; + +typedef __attribute__((ext_vector_type(2))) int int2; typedef __attribute__((ext_vector_type(4))) int int4; +typedef __attribute__((ext_vector_type(16))) int int16; int printf(__constant const char* st, ...) __attribute__((format(printf, 1, 2))); kernel void format_v4f32(float4 arg) { - printf("%v4f\n", arg); // expected-no-diagnostics +#ifdef cl_khr_fp64 + printf("%v4f\n", arg); + + // Precision modifier + printf("%.2v4f\n", arg); +#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)}} + + // Precision modifier + printf("%.2v4f\n", arg); // expected-warning {{double __attribute__((ext_vector_type(4)))' but the argument has type 'float4' (vector of 4 'float' values)}} +#endif } -kernel void format_v4f32_wrong_num_elts(float2 arg) +kernel void format_only_v(int arg) { - printf("%v4f\n", arg); // expected-no-diagnostics + printf("%v", arg); // expected-warning {{incomplete format specifier}} } -kernel void vector_precision_modifier_v4f32(float4 arg) +kernel void format_missing_num(int arg) { - printf("%.2v4f\n", arg); // expected-no-diagnostics + printf("%v4", arg); // expected-warning {{incomplete format specifier}} +} + +kernel void format_not_num(int arg) +{ + printf("%vNd", arg); // expected-warning {{incomplete format specifier}} + printf("%v*d", arg); // expected-warning {{incomplete format specifier}} +} + +kernel void format_v16i32(int16 arg) +{ + printf("%v16d\n", arg); +} + +kernel void format_v4i32_scalar(int arg) +{ + printf("%v4d\n", arg); // expected-warning {{format specifies type 'int __attribute__((ext_vector_type(4)))' but the argument has type 'int'}} +} + +kernel void format_v4i32_wrong_num_elts_2_to_4(int2 arg) +{ + 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)}} +} + +kernel void format_missing_num_elts_format(int4 arg) +{ + printf("%vd\n", arg); // expected-warning {{incomplete format specifier}} +} + +kernel void format_v4f32_scalar(float arg) +{ + printf("%v4f\n", arg); // expected-warning {{format specifies type 'double __attribute__((ext_vector_type(4)))' but the argument has type 'float'}} +} + +kernel void format_v4f32_wrong_num_elts(float2 arg) +{ + 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)}} } -// FIXME: This should warn kernel void format_missing_num_elts(float4 arg) { - printf("%vf\n", arg); // expected-no-diagnostics + printf("%vf\n", arg); // expected-warning {{incomplete format specifier}} +} + +kernel void vector_precision_modifier_v4i32_to_v4f32(int4 arg) +{ + 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)}} +} + +kernel void invalid_Y(int4 arg) +{ + printf("%v4Y\n", arg); // expected-warning {{invalid conversion specifier 'Y'}} } // FIXME: This should warn -kernel void vector_precision_modifier_v4i32(int4 arg) +kernel void crash_on_s(int4 arg) { - printf("%.2v4f\n", arg); // expected-no-diagnostics + printf("%v4s\n", arg); } |