[PATCH] D78777: [AST] Use PrintingPolicy for format string diagnosis

Jessica Clarke via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Apr 23 17:57:41 PDT 2020


jrtc27 created this revision.
jrtc27 added reviewers: rsmith, Anastasia.
Herald added subscribers: cfe-commits, arichardson.
Herald added a project: clang.

This is a small improvement for OpenCL diagnostics, but is also useful
for our CHERI fork, as our __capability qualifier is suppressed from
diagnostics when all pointers are capabilities, only being used when pointers
need to be explicitly opted-in to being capabilities.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D78777

Files:
  clang/lib/AST/FormatString.cpp
  clang/test/SemaOpenCL/printf-format-strings.cl


Index: clang/test/SemaOpenCL/printf-format-strings.cl
===================================================================
--- clang/test/SemaOpenCL/printf-format-strings.cl
+++ clang/test/SemaOpenCL/printf-format-strings.cl
@@ -65,8 +65,8 @@
 
 kernel void format_v4f16(half4 arg_h, float4 arg_f, double4 arg_d)
 {
-  printf("%v4hf\n", arg_d); // expected-warning{{format specifies type '__fp16 __attribute__((ext_vector_type(4)))' but the argument has type 'double4' (vector of 4 'double' values)}}
-  printf("%v4hf\n", arg_f); // expected-warning{{format specifies type '__fp16 __attribute__((ext_vector_type(4)))' but the argument has type 'float4' (vector of 4 'float' values)}}
+  printf("%v4hf\n", arg_d); // expected-warning{{format specifies type 'half __attribute__((ext_vector_type(4)))' but the argument has type 'double4' (vector of 4 'double' values)}}
+  printf("%v4hf\n", arg_f); // expected-warning{{format specifies type 'half __attribute__((ext_vector_type(4)))' but the argument has type 'float4' (vector of 4 'float' values)}}
   printf("%v4hf\n", arg_h);
 }
 
Index: clang/lib/AST/FormatString.cpp
===================================================================
--- clang/lib/AST/FormatString.cpp
+++ clang/lib/AST/FormatString.cpp
@@ -539,7 +539,7 @@
 }
 
 std::string ArgType::getRepresentativeTypeName(ASTContext &C) const {
-  std::string S = getRepresentativeType(C).getAsString();
+  std::string S = getRepresentativeType(C).getAsString(C.getPrintingPolicy());
 
   std::string Alias;
   if (Name) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D78777.259764.patch
Type: text/x-patch
Size: 1531 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200424/cc7fe7f9/attachment.bin>


More information about the cfe-commits mailing list