[PATCH] D54162: OpenCL: Don't warn on v printf modifier

2018-11-13 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm closed this revision.
arsenm added a comment.

r346806


https://reviews.llvm.org/D54162



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D54162: OpenCL: Don't warn on v printf modifier

2018-11-06 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia accepted this revision.
Anastasia added a comment.
This revision is now accepted and ready to land.

LGTM! Thanks! Seems like a reasonable start.


https://reviews.llvm.org/D54162



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D54162: OpenCL: Don't warn on v printf modifier

2018-11-06 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm created this revision.
arsenm added a reviewer: Anastasia.
Herald added subscribers: yaxunl, wdng.

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.


https://reviews.llvm.org/D54162

Files:
  include/clang/AST/FormatString.h
  lib/AST/FormatString.cpp
  lib/AST/PrintfFormatString.cpp
  test/Sema/format-strings.c
  test/SemaOpenCL/printf-format-strings.cl

Index: test/SemaOpenCL/printf-format-strings.cl
===
--- /dev/null
+++ 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
+}
Index: test/Sema/format-strings.c
===
--- test/Sema/format-strings.c
+++ test/Sema/format-strings.c
@@ -613,6 +613,11 @@
   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 *, ...)
Index: lib/AST/PrintfFormatString.cpp
===
--- lib/AST/PrintfFormatString.cpp
+++ lib/AST/PrintfFormatString.cpp
@@ -347,6 +347,12 @@
 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
@@ -1008,6 +1014,7 @@
   case ConversionSpecifier::FreeBSDrArg:
   case ConversionSpecifier::FreeBSDyArg:
   case ConversionSpecifier::PArg:
+  case ConversionSpecifier::VArg:
 return true;
 
   default:
Index: lib/AST/FormatString.cpp
===
--- lib/AST/FormatString.cpp
+++ lib/AST/FormatString.cpp
@@ -618,6 +618,9 @@
 
   // MS specific specifiers.
   case ZArg: return "Z";
+
+ // OpenCL specific specifiers.
+  case VArg: return "v";
   }
   return nullptr;
 }
@@ -875,6 +878,8 @@
 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: include/clang/AST/FormatString.h
===
--- include/clang/AST/FormatString.h
+++ include/clang/AST/FormatString.h
@@ -166,6 +166,8 @@
 
 ZArg, // MS extension
 
+VArg, // OpenCL vectors
+
 // Objective-C specific specifiers.
 ObjCObjArg, // '@'
 ObjCBeg = ObjCObjArg,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits