]> granicus.if.org Git - clang/commitdiff
[OpenCL] Allow function declaration with empty argument list.
authorAlexey Bader <alexey.bader@intel.com>
Thu, 29 Jun 2017 08:44:10 +0000 (08:44 +0000)
committerAlexey Bader <alexey.bader@intel.com>
Thu, 29 Jun 2017 08:44:10 +0000 (08:44 +0000)
Summary:
does it make sense to enable K&R function declaration style for OpenCL?
clang throws following error message for the declaration w/o arguments:

```
int my_func();
error: function with no prototype cannot use the spir_function calling convention
```

Current way to fix this issue is to specify that parameter list is empty by using 'void':

```
int my_func(void);
```

Let me know what do you think about this patch.

Reviewers: Anastasia, yaxunl

Reviewed By: Anastasia

Subscribers: cfe-commits, echuraev

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306653 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaType.cpp
test/SemaOpenCL/function-no-args.cl [new file with mode: 0644]
test/SemaOpenCL/invalid-pipes-cl2.0.cl

index 8c8402e75e3781c6d3768143385e6fb8aedb8996..465e8d146dd2dcc22e53fe482c5e1ed2f4b9ab62 100644 (file)
@@ -4355,7 +4355,7 @@ static TypeSourceInfo *GetFullTypeForDeclarator(TypeProcessingState &state,
 
       FunctionType::ExtInfo EI(getCCForDeclaratorChunk(S, D, FTI, chunkIndex));
 
-      if (!FTI.NumParams && !FTI.isVariadic && !LangOpts.CPlusPlus) {
+      if (!FTI.NumParams && !FTI.isVariadic && !LangOpts.CPlusPlus  && !LangOpts.OpenCL) {
         // Simple void foo(), where the incoming T is the result type.
         T = Context.getFunctionNoProtoType(T, EI);
       } else {
diff --git a/test/SemaOpenCL/function-no-args.cl b/test/SemaOpenCL/function-no-args.cl
new file mode 100644 (file)
index 0000000..12070a5
--- /dev/null
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -verify -pedantic -fsyntax-only -cl-std=CL2.0 %s
+// expected-no-diagnostics
+
+global int gi;
+int my_func();
+int my_func() {
+  gi = 2;
+  return gi;
+}
index a50811650d2c7dc9bce24b506fd99cdfad8dd9a2..463fd3d0dabc19cf9be9585679b2e78e06215cb7 100644 (file)
@@ -3,7 +3,7 @@
 global pipe int gp;            // expected-error {{type '__global read_only pipe int' can only be used as a function parameter in OpenCL}}
 global reserve_id_t rid;          // expected-error {{the '__global reserve_id_t' type cannot be used to declare a program scope variable}}
 
-extern pipe write_only int get_pipe(); // expected-error {{type '__global write_only pipe int ()' can only be used as a function parameter in OpenCL}}
+extern pipe write_only int get_pipe(); // expected-error {{type '__global write_only pipe int (void)' can only be used as a function parameter in OpenCL}}
 
 kernel void test_invalid_reserved_id(reserve_id_t ID) { // expected-error {{'reserve_id_t' cannot be used as the type of a kernel parameter}}
 }