From caaaf1b95ed9e016f314b61bf74453da91dda1ce Mon Sep 17 00:00:00 2001 From: Alexey Bader Date: Wed, 11 Oct 2017 11:16:31 +0000 Subject: [PATCH] [OpenCL] Allow function declaration with empty argument list. 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 | 3 ++- lib/Sema/SemaType.cpp | 3 ++- test/SemaOpenCL/func.cl | 5 ++++- test/SemaOpenCL/invalid-pipes-cl2.0.cl | 2 +- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/Parse/ParseDecl.cpp b/lib/Parse/ParseDecl.cpp index 8bca7badea..098bf9b12d 100644 --- a/lib/Parse/ParseDecl.cpp +++ b/lib/Parse/ParseDecl.cpp @@ -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(); diff --git a/lib/Sema/SemaType.cpp b/lib/Sema/SemaType.cpp index fb3f41ec0f..8623ab0b21 100644 --- a/lib/Sema/SemaType.cpp +++ b/lib/Sema/SemaType.cpp @@ -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 { diff --git a/test/SemaOpenCL/func.cl b/test/SemaOpenCL/func.cl index dc5b44057b..83c3b4a6bc 100644 --- a/test/SemaOpenCL/func.cl +++ b/test/SemaOpenCL/func.cl @@ -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 diff --git a/test/SemaOpenCL/invalid-pipes-cl2.0.cl b/test/SemaOpenCL/invalid-pipes-cl2.0.cl index a50811650d..463fd3d0da 100644 --- a/test/SemaOpenCL/invalid-pipes-cl2.0.cl +++ b/test/SemaOpenCL/invalid-pipes-cl2.0.cl @@ -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}} } -- 2.49.0