소스 검색

OpenCL: Mark printf format string argument

Fixes not warning on format string errors.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@343653 91177308-0d34-0410-b5e6-96231b3b80d8
Matt Arsenault 6 년 전
부모
커밋
5a76d40916
2개의 변경된 파일14개의 추가작업 그리고 1개의 파일을 삭제
  1. 1 1
      lib/Headers/opencl-c.h
  2. 13 0
      test/SemaOpenCL/printf-format-string-warnings.cl

+ 1 - 1
lib/Headers/opencl-c.h

@@ -14462,7 +14462,7 @@ half16 __ovld __cnfn shuffle2(half16 x, half16 y, ushort16 mask);
 #if __OPENCL_C_VERSION__ >= CL_VERSION_1_2
 #if __OPENCL_C_VERSION__ >= CL_VERSION_1_2
 // OpenCL v1.2 s6.12.13, v2.0 s6.13.13 - printf
 // 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
 #endif
 
 
 // OpenCL v1.1 s6.11.3, v1.2 s6.12.14, v2.0 s6.13.14 - Image Read and Write Functions
 // OpenCL v1.1 s6.11.3, v1.2 s6.12.14, v2.0 s6.13.14 - Image Read and Write Functions

+ 13 - 0
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}}
+}