r342638 - [OpenCL] Diagnose redundant address space conversion

Sven van Haastregt via cfe-commits cfe-commits at lists.llvm.org
Thu Sep 20 03:07:27 PDT 2018


Author: svenvh
Date: Thu Sep 20 03:07:27 2018
New Revision: 342638

URL: http://llvm.org/viewvc/llvm-project?rev=342638&view=rev
Log:
[OpenCL] Diagnose redundant address space conversion

Add a warning if a parameter with a named address space is passed
to a to_addr builtin.

For example:

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

Patch by Alistair Davies.

Differential Revision: https://reviews.llvm.org/D51411

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/SemaChecking.cpp
    cfe/trunk/test/SemaOpenCL/to_addr_builtin.cl

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=342638&r1=342637&r2=342638&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Thu Sep 20 03:07:27 2018
@@ -8613,6 +8613,10 @@ def err_opencl_variadic_function : Error
   "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"
+  " may cause dynamic conversion affecting performance">,
+  InGroup<Conversion>, DefaultIgnore;
 
 // OpenCL v2.0 s6.13.6 -- Builtin Pipe Functions
 def err_opencl_builtin_pipe_first_arg : Error<

Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=342638&r1=342637&r2=342638&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Thu Sep 20 03:07:27 2018
@@ -849,6 +849,13 @@ static bool SemaOpenCLBuiltinToAddr(Sema
     return true;
   }
 
+  if (RT->getPointeeType().getAddressSpace() != LangAS::opencl_generic) {
+    S.Diag(Call->getArg(0)->getBeginLoc(),
+           diag::warn_opencl_generic_address_space_arg)
+        << Call->getDirectCallee()->getNameInfo().getAsString()
+        << Call->getArg(0)->getSourceRange();
+  }
+
   RT = RT->getPointeeType();
   auto Qual = RT.getQualifiers();
   switch (BuiltinID) {

Modified: cfe/trunk/test/SemaOpenCL/to_addr_builtin.cl
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCL/to_addr_builtin.cl?rev=342638&r1=342637&r2=342638&view=diff
==============================================================================
--- cfe/trunk/test/SemaOpenCL/to_addr_builtin.cl (original)
+++ cfe/trunk/test/SemaOpenCL/to_addr_builtin.cl Thu Sep 20 03:07:27 2018
@@ -1,5 +1,5 @@
 // RUN: %clang_cc1 -verify -fsyntax-only %s
-// RUN: %clang_cc1 -verify -fsyntax-only -cl-std=CL2.0 %s
+// RUN: %clang_cc1 -Wconversion -verify -fsyntax-only -cl-std=CL2.0 %s
 
 void test(void) {
   global int *glob;
@@ -43,6 +43,7 @@ void test(void) {
   // 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 may cause dynamic conversion affecting performance}}
 #endif
 
   global char *glob_c = to_global(loc);
@@ -50,6 +51,7 @@ void test(void) {
   // 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 may cause dynamic conversion affecting performance}}
 #endif
 
 }




More information about the cfe-commits mailing list