[PATCH] D52412: OpenCL: Mark printf format string argument

Matt Arsenault via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Sep 24 07:21:35 PDT 2018


arsenm created this revision.
arsenm added a reviewer: Anastasia.
Herald added subscribers: yaxunl, wdng.

Fixes not warning on format string errors.


https://reviews.llvm.org/D52412

Files:
  lib/Headers/opencl-c.h
  test/SemaOpenCL/printf-format-string-warnings.cl


Index: test/SemaOpenCL/printf-format-string-warnings.cl
===================================================================
--- /dev/null
+++ test/SemaOpenCL/printf-format-string-warnings.cl
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL2.0 -finclude-default-header
+
+// Make sure warnings are produced based on printf format strings.
+
+
+kernel void format_string_warnings(__constant char* arg) {
+
+  printf("%d", arg); // expected-warning {{format specifies type 'int' but the argument has type '__constant char *'}}
+
+  printf("not enough arguments %d %d", 4); // expected-warning {{more '%' conversions than data arguments}}
+
+  printf("too many arguments", 4); // expected-warning {{data argument not used by format string}}
+}
Index: lib/Headers/opencl-c.h
===================================================================
--- lib/Headers/opencl-c.h
+++ lib/Headers/opencl-c.h
@@ -14462,7 +14462,7 @@
 #if __OPENCL_C_VERSION__ >= CL_VERSION_1_2
 // OpenCL v1.2 s6.12.13, v2.0 s6.13.13 - printf
 
-int printf(__constant const char* st, ...);
+int printf(__constant const char* st, ...) __attribute__((format(printf, 1, 2)));
 #endif
 
 // OpenCL v1.1 s6.11.3, v1.2 s6.12.14, v2.0 s6.13.14 - Image Read and Write Functions


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D52412.166657.patch
Type: text/x-patch
Size: 1270 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180924/3f5964b8/attachment.bin>


More information about the cfe-commits mailing list