r343653 - OpenCL: Mark printf format string argument

Anastasia Stulova via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 29 12:10:08 PDT 2018


It seems like it caused a bug:

https://bugs.llvm.org/show_bug.cgi?id=39486


________________________________
From: cfe-commits <cfe-commits-bounces at lists.llvm.org> on behalf of Matt Arsenault via cfe-commits <cfe-commits at lists.llvm.org>
Sent: 03 October 2018 03:01
To: cfe-commits at lists.llvm.org
Subject: r343653 - OpenCL: Mark printf format string argument

Author: arsenm
Date: Tue Oct  2 19:01:19 2018
New Revision: 343653

URL: http://llvm.org/viewvc/llvm-project?rev=343653&view=rev
Log:
OpenCL: Mark printf format string argument

Fixes not warning on format string errors.

Added:
    cfe/trunk/test/SemaOpenCL/printf-format-string-warnings.cl
Modified:
    cfe/trunk/lib/Headers/opencl-c.h

Modified: cfe/trunk/lib/Headers/opencl-c.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/opencl-c.h?rev=343653&r1=343652&r2=343653&view=diff
==============================================================================
--- cfe/trunk/lib/Headers/opencl-c.h (original)
+++ cfe/trunk/lib/Headers/opencl-c.h Tue Oct  2 19:01:19 2018
@@ -14462,7 +14462,7 @@ half16 __ovld __cnfn shuffle2(half16 x,
 #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

Added: cfe/trunk/test/SemaOpenCL/printf-format-string-warnings.cl
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCL/printf-format-string-warnings.cl?rev=343653&view=auto
==============================================================================
--- cfe/trunk/test/SemaOpenCL/printf-format-string-warnings.cl (added)
+++ cfe/trunk/test/SemaOpenCL/printf-format-string-warnings.cl Tue Oct  2 19:01:19 2018
@@ -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}}
+}


_______________________________________________
cfe-commits mailing list
cfe-commits at lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20181029/3f1f9611/attachment-0001.html>


More information about the cfe-commits mailing list