]> granicus.if.org Git - clang/commitdiff
[OpenCL] Allow function declaration with empty argument list.
authorAlexey Bader <alexey.bader@intel.com>
Wed, 11 Oct 2017 11:16:31 +0000 (11:16 +0000)
committerAlexey Bader <alexey.bader@intel.com>
Wed, 11 Oct 2017 11:16:31 +0000 (11:16 +0000)
Treat 'f()' as 'f(void)' rather than a function w/o a prototype.

Reviewers: Anastasia, yaxunl

Reviewed By: Anastasia, yaxunl

Subscribers: cfe-commits, echuraev, chapuni

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

Re-apply revision 306653.

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

lib/Parse/ParseDecl.cpp
lib/Sema/SemaType.cpp
test/SemaOpenCL/func.cl
test/SemaOpenCL/invalid-pipes-cl2.0.cl

index 8bca7badea2278484e15548edb20887d9e92b576..098bf9b12d7ff915f2adf7795784bdb69377ac28 100644 (file)
@@ -5989,7 +5989,8 @@ void Parser::ParseFunctionDeclarator(Declarator &D,
     else if (RequiresArg)
       Diag(Tok, diag::err_argument_required_after_attribute);
 
-    HasProto = ParamInfo.size() || getLangOpts().CPlusPlus;
+    HasProto = ParamInfo.size() || getLangOpts().CPlusPlus
+                                || getLangOpts().OpenCL;
 
     // If we have the closing ')', eat it.
     Tracker.consumeClose();
index fb3f41ec0f67cafcb22bd372f3e728a482f04e46..8623ab0b2189202a6c3183d3cf05a3ae242d0e5e 100644 (file)
@@ -4460,7 +4460,8 @@ 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 {
index dc5b44057b19ffbacb60c3ed973e40f322adced1..83c3b4a6bcf9089074d270a74d06ea7fe1f1b208 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -triple spir-unknown-unknown
 
 // Variadic functions
 void vararg_f(int, ...);                    // expected-error {{invalid prototype, variadic arguments are not allowed in OpenCL}}
@@ -16,6 +16,9 @@ typedef struct s
 //Function pointer
 void foo(void*);
 
+// Expect no diagnostics for an empty parameter list.
+void bar();
+
 void bar()
 {
   // declaring a function pointer is an error
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}}
 }