[PATCH] D51411: [OpenCL] Improve diagnostic of argument in address space conversion builtins

Alistair Davies via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 29 04:01:51 PDT 2018


AlistairD created this revision.
AlistairD added a reviewer: yaxunl.

This change adds a warning if a parameter is passed with named address space to parameter that is in generic address space.

For example:

  int i;
  to_private(&i); //generate warning as conversion from private to private is redundant.


https://reviews.llvm.org/D51411

Files:
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/Sema/SemaChecking.cpp
  test/Misc/warning-flags.c
  test/SemaOpenCL/to_addr_builtin.cl


Index: test/SemaOpenCL/to_addr_builtin.cl
===================================================================
--- test/SemaOpenCL/to_addr_builtin.cl
+++ test/SemaOpenCL/to_addr_builtin.cl
@@ -43,13 +43,14 @@
   // expected-warning at -2{{incompatible integer to pointer conversion assigning to '__local int *' from 'int'}}
 #else
   // expected-error at -4{{assigning '__global int *' to '__local int *' changes address space of pointer}}
+  // expected-warning at -5{{passing non-generic address space pointer to to_global generates dynamic conversion where it is not needed}}
 #endif
 
   global char *glob_c = to_global(loc);
 #if __OPENCL_C_VERSION__ < CL_VERSION_2_0
   // expected-warning at -2{{incompatible integer to pointer conversion initializing '__global char *' with an expression of type 'int'}}
 #else
   // expected-warning at -4{{incompatible pointer types initializing '__global char *' with an expression of type '__global int *'}}
+  // expected-warning at -5{{passing non-generic address space pointer to to_global generates dynamic conversion where it is not needed}}
 #endif
-
 }
Index: test/Misc/warning-flags.c
===================================================================
--- test/Misc/warning-flags.c
+++ test/Misc/warning-flags.c
@@ -18,7 +18,7 @@
 
 The list of warnings below should NEVER grow.  It should gradually shrink to 0.
 
-CHECK: Warnings without flags (76):
+CHECK: Warnings without flags (77):
 CHECK-NEXT:   ext_excess_initializers
 CHECK-NEXT:   ext_excess_initializers_in_char_array_initializer
 CHECK-NEXT:   ext_expected_semi_decl_list
@@ -77,6 +77,7 @@
 CHECK-NEXT:   warn_objc_property_copy_missing_on_block
 CHECK-NEXT:   warn_objc_protocol_qualifier_missing_id
 CHECK-NEXT:   warn_on_superclass_use
+CHECK-NEXT:   warn_opencl_generic_address_space_arg
 CHECK-NEXT:   warn_pp_convert_to_positive
 CHECK-NEXT:   warn_pp_expr_overflow
 CHECK-NEXT:   warn_pp_line_decimal
Index: lib/Sema/SemaChecking.cpp
===================================================================
--- lib/Sema/SemaChecking.cpp
+++ lib/Sema/SemaChecking.cpp
@@ -839,6 +839,13 @@
     return true;
   }
 
+  if (RT->getPointeeType().getAddressSpace() != LangAS::opencl_generic) {
+    S.Diag(Call->getArg(0)->getLocStart(),
+           diag::warn_opencl_generic_address_space_arg)
+        << Call->getDirectCallee()->getNameInfo().getAsString()
+        << Call->getArg(0)->getSourceRange();
+  }
+
   RT = RT->getPointeeType();
   auto Qual = RT.getQualifiers();
   switch (BuiltinID) {
Index: include/clang/Basic/DiagnosticSemaKinds.td
===================================================================
--- include/clang/Basic/DiagnosticSemaKinds.td
+++ include/clang/Basic/DiagnosticSemaKinds.td
@@ -8579,6 +8579,9 @@
   "invalid prototype, variadic arguments are not allowed in OpenCL">;
 def err_opencl_requires_extension : Error<
   "use of %select{type|declaration}0 %1 requires %2 extension to be enabled">;
+def warn_opencl_generic_address_space_arg : Warning<
+  "passing non-generic address space pointer to %0"
+  " generates dynamic conversion where it is not needed">;
 
 // OpenCL v2.0 s6.13.6 -- Builtin Pipe Functions
 def err_opencl_builtin_pipe_first_arg : Error<


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D51411.163042.patch
Type: text/x-patch
Size: 3194 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180829/f17a791f/attachment-0001.bin>


More information about the cfe-commits mailing list