r198597 - [OpenCL] Produce an error if an address space is used on the return

Joey Gouly joey.gouly at gmail.com
Mon Jan 6 03:26:19 PST 2014


Author: joey
Date: Mon Jan  6 05:26:18 2014
New Revision: 198597

URL: http://llvm.org/viewvc/llvm-project?rev=198597&view=rev
Log:
[OpenCL] Produce an error if an address space is used on the return
type of a function.

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/test/SemaOpenCL/invalid-kernel.cl

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=198597&r1=198596&r2=198597&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Mon Jan  6 05:26:18 2014
@@ -6714,6 +6714,8 @@ def err_opencl_global_invalid_addr_space
 def err_opencl_no_main : Error<"%select{function|kernel}0 cannot be called 'main'">;
 def err_opencl_kernel_attr :
   Error<"attribute %0 can only be applied to a kernel function">;
+def err_opencl_return_value_with_address_space : Error<
+  "return value cannot be qualified with address space">;
 def err_opencl_constant_no_init : Error<
   "variable in constant address space must be initialized">;
 } // end of sema category

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=198597&r1=198596&r2=198597&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Mon Jan  6 05:26:18 2014
@@ -7030,6 +7030,19 @@ Sema::ActOnFunctionDeclarator(Scope *S,
     }
   }
 
+  if (getLangOpts().OpenCL) {
+    // OpenCL v1.1 s6.5: Using an address space qualifier in a function return
+    // type declaration will generate a compilation error.
+    unsigned AddressSpace = RetType.getAddressSpace();
+    if (AddressSpace == LangAS::opencl_local ||
+        AddressSpace == LangAS::opencl_global ||
+        AddressSpace == LangAS::opencl_constant) {
+      Diag(NewFD->getLocation(),
+           diag::err_opencl_return_value_with_address_space);
+      NewFD->setInvalidDecl();
+    }
+  }
+
   if (!getLangOpts().CPlusPlus) {
     // Perform semantic checking on the function declaration.
     bool isExplicitSpecialization=false;

Modified: cfe/trunk/test/SemaOpenCL/invalid-kernel.cl
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCL/invalid-kernel.cl?rev=198597&r1=198596&r2=198597&view=diff
==============================================================================
--- cfe/trunk/test/SemaOpenCL/invalid-kernel.cl (original)
+++ cfe/trunk/test/SemaOpenCL/invalid-kernel.cl Mon Jan  6 05:26:18 2014
@@ -13,3 +13,15 @@ kernel void main() { // expected-error {
 int main() { // expected-error {{function cannot be called 'main'}}
   return 0;
 }
+
+int* global x(int* x) { // expected-error {{return value cannot be qualified with address space}}
+  return x + 1;
+}
+
+int* local x(int* x) { // expected-error {{return value cannot be qualified with address space}}
+  return x + 1;
+}
+
+int* constant x(int* x) { // expected-error {{return value cannot be qualified with address space}}
+  return x + 1;
+}





More information about the cfe-commits mailing list