summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang/include/clang/AST/FormatString.h2
-rw-r--r--clang/lib/AST/FormatString.cpp5
-rw-r--r--clang/lib/AST/PrintfFormatString.cpp7
-rw-r--r--clang/test/Sema/format-strings.c5
-rw-r--r--clang/test/SemaOpenCL/printf-format-strings.cl34
5 files changed, 53 insertions, 0 deletions
diff --git a/clang/include/clang/AST/FormatString.h b/clang/include/clang/AST/FormatString.h
index 1e341f38402..4170d718aea 100644
--- a/clang/include/clang/AST/FormatString.h
+++ b/clang/include/clang/AST/FormatString.h
@@ -166,6 +166,8 @@ public:
ZArg, // MS extension
+ VArg, // OpenCL vectors
+
// Objective-C specific specifiers.
ObjCObjArg, // '@'
ObjCBeg = ObjCObjArg,
diff --git a/clang/lib/AST/FormatString.cpp b/clang/lib/AST/FormatString.cpp
index 5e2137c7088..565bd03a7bb 100644
--- a/clang/lib/AST/FormatString.cpp
+++ b/clang/lib/AST/FormatString.cpp
@@ -618,6 +618,9 @@ const char *ConversionSpecifier::toString() const {
// MS specific specifiers.
case ZArg: return "Z";
+
+ // OpenCL specific specifiers.
+ case VArg: return "v";
}
return nullptr;
}
@@ -875,6 +878,8 @@ bool FormatSpecifier::hasStandardConversionSpecifier(
case ConversionSpecifier::CArg:
case ConversionSpecifier::SArg:
return LangOpt.ObjC;
+ case ConversionSpecifier::VArg:
+ return LangOpt.OpenCL;
case ConversionSpecifier::InvalidSpecifier:
case ConversionSpecifier::FreeBSDbArg:
case ConversionSpecifier::FreeBSDDArg:
diff --git a/clang/lib/AST/PrintfFormatString.cpp b/clang/lib/AST/PrintfFormatString.cpp
index f22c4f8f644..877f89055ab 100644
--- a/clang/lib/AST/PrintfFormatString.cpp
+++ b/clang/lib/AST/PrintfFormatString.cpp
@@ -362,6 +362,12 @@ static PrintfSpecifierResult ParsePrintfSpecifier(FormatStringHandler &H,
case 'Z':
if (Target.getTriple().isOSMSVCRT())
k = ConversionSpecifier::ZArg;
+ break;
+ // OpenCL specific.
+ case 'v':
+ if (LO.OpenCL)
+ k = ConversionSpecifier::VArg;
+ break;
}
// Check to see if we used the Objective-C modifier flags with
@@ -1026,6 +1032,7 @@ bool PrintfSpecifier::hasValidPrecision() const {
case ConversionSpecifier::FreeBSDrArg:
case ConversionSpecifier::FreeBSDyArg:
case ConversionSpecifier::PArg:
+ case ConversionSpecifier::VArg:
return true;
default:
diff --git a/clang/test/Sema/format-strings.c b/clang/test/Sema/format-strings.c
index 5cfa5b4747a..a9af8ce5dee 100644
--- a/clang/test/Sema/format-strings.c
+++ b/clang/test/Sema/format-strings.c
@@ -613,6 +613,11 @@ void pr12761(char c) {
printf("%hhx", c);
}
+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'}}
+}
// Test that we correctly merge the format in both orders.
extern void test14_foo(const char *, const char *, ...)
diff --git a/clang/test/SemaOpenCL/printf-format-strings.cl b/clang/test/SemaOpenCL/printf-format-strings.cl
new file mode 100644
index 00000000000..d5748e18ede
--- /dev/null
+++ b/clang/test/SemaOpenCL/printf-format-strings.cl
@@ -0,0 +1,34 @@
+// RUN: %clang_cc1 -cl-std=CL1.2 -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(4))) int int4;
+
+int printf(__constant const char* st, ...) __attribute__((format(printf, 1, 2)));
+
+kernel void format_v4f32(float4 arg)
+{
+ printf("%v4f\n", arg); // expected-no-diagnostics
+}
+
+kernel void format_v4f32_wrong_num_elts(float2 arg)
+{
+ printf("%v4f\n", arg); // expected-no-diagnostics
+}
+
+kernel void vector_precision_modifier_v4f32(float4 arg)
+{
+ printf("%.2v4f\n", arg); // expected-no-diagnostics
+}
+
+// FIXME: This should warn
+kernel void format_missing_num_elts(float4 arg)
+{
+ printf("%vf\n", arg); // expected-no-diagnostics
+}
+
+// FIXME: This should warn
+kernel void vector_precision_modifier_v4i32(int4 arg)
+{
+ printf("%.2v4f\n", arg); // expected-no-diagnostics
+}
OpenPOWER on IntegriCloud