]> granicus.if.org Git - clang/commitdiff
OpenCL: Don't warn on v printf modifier
authorMatt Arsenault <Matthew.Arsenault@amd.com>
Tue, 13 Nov 2018 22:30:35 +0000 (22:30 +0000)
committerMatt Arsenault <Matthew.Arsenault@amd.com>
Tue, 13 Nov 2018 22:30:35 +0000 (22:30 +0000)
This avoids spurious warnings, but could use
a lot of work. For example the number of vector
elements is not verified, and the passed
value type is not checked.

Fixes bug 39486

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@346806 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/FormatString.h
lib/AST/FormatString.cpp
lib/AST/PrintfFormatString.cpp
test/Sema/format-strings.c
test/SemaOpenCL/printf-format-strings.cl [new file with mode: 0644]

index 1e341f384026a2b400aba364b3d5785908ab4c36..4170d718aea2d3c83d653b264b02c3c3cf451cf7 100644 (file)
@@ -166,6 +166,8 @@ public:
 
     ZArg, // MS extension
 
+    VArg, // OpenCL vectors
+
     // Objective-C specific specifiers.
     ObjCObjArg, // '@'
     ObjCBeg = ObjCObjArg,
index 5e2137c7088f530400ed1f7c3db62cb6ab363b03..565bd03a7bba6be5d43ba098a1804a68d8800853 100644 (file)
@@ -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:
index f22c4f8f64405951e1d65d24fbf48c6c7d6e1dac..877f89055abd2da44904da4419dde988b83c0831 100644 (file)
@@ -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:
index 5cfa5b4747a1a5facaf559006c817cd67d599399..a9af8ce5dee9ea0a5700211f7ada11fb868ec53c 100644 (file)
@@ -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/test/SemaOpenCL/printf-format-strings.cl b/test/SemaOpenCL/printf-format-strings.cl
new file mode 100644 (file)
index 0000000..d5748e1
--- /dev/null
@@ -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
+}