[PATCH] D112110: [OpenCL] queue_t and ndrange_t can't be defined in program scope.
cycheng updated this revision to Diff 382813. cycheng marked 2 inline comments as done. cycheng added a comment. - Remove OpenCL 2.0 description - Merge test files into single test file CHANGES SINCE LAST ACTION https://reviews.llvm.org/D112110/new/ https://reviews.llvm.org/D112110 Files: clang/lib/Sema/SemaDecl.cpp clang/test/SemaOpenCL/invalid-ndrange.cl clang/test/SemaOpenCL/invalid-queue.cl Index: clang/test/SemaOpenCL/invalid-queue.cl === --- /dev/null +++ clang/test/SemaOpenCL/invalid-queue.cl @@ -0,0 +1,4 @@ +// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL2.0 +// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL3.0 -cl-ext=+__opencl_c_device_enqueue + +global queue_t qt; // expected-error {{the '__global queue_t' type cannot be used to declare a program scope variable}} Index: clang/test/SemaOpenCL/invalid-ndrange.cl === --- /dev/null +++ clang/test/SemaOpenCL/invalid-ndrange.cl @@ -0,0 +1,6 @@ +// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL2.0 +// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL3.0 + +typedef struct {int a;} ndrange_t; + +global ndrange_t qt; // expected-error {{the '__global ndrange_t' type cannot be used to declare a program scope variable}} Index: clang/lib/Sema/SemaDecl.cpp === --- clang/lib/Sema/SemaDecl.cpp +++ clang/lib/Sema/SemaDecl.cpp @@ -6841,8 +6841,16 @@ // OpenCL v2.0 s6.9.q: // The clk_event_t and reserve_id_t types cannot be declared in program // scope. + // OpenCL v2.0 s6.5.1: + // Variables defined at program scope and static variables inside a function + // can also be declared in the global address space. They can be defined with + // any valid OpenCL C data type except for those in Other Built-in Data Types. + // OpenCL v3.0 s6.11.w: + // Program scope variables can be defined with any valid OpenCL C data type + // except for those in Other Built-in Data Types. if (NewVD->hasGlobalStorage() && !NewVD->isStaticLocal()) { -if (R->isReserveIDT() || R->isClkEventT() || R->isEventT()) { +if (R->isReserveIDT() || R->isClkEventT() || R->isEventT() || +R.getUnqualifiedType().getAsString() == "ndrange_t" || R->isQueueT()) { Se.Diag(NewVD->getLocation(), diag::err_invalid_type_for_program_scope_var) << R; Index: clang/test/SemaOpenCL/invalid-queue.cl === --- /dev/null +++ clang/test/SemaOpenCL/invalid-queue.cl @@ -0,0 +1,4 @@ +// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL2.0 +// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL3.0 -cl-ext=+__opencl_c_device_enqueue + +global queue_t qt; // expected-error {{the '__global queue_t' type cannot be used to declare a program scope variable}} Index: clang/test/SemaOpenCL/invalid-ndrange.cl === --- /dev/null +++ clang/test/SemaOpenCL/invalid-ndrange.cl @@ -0,0 +1,6 @@ +// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL2.0 +// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL3.0 + +typedef struct {int a;} ndrange_t; + +global ndrange_t qt; // expected-error {{the '__global ndrange_t' type cannot be used to declare a program scope variable}} Index: clang/lib/Sema/SemaDecl.cpp === --- clang/lib/Sema/SemaDecl.cpp +++ clang/lib/Sema/SemaDecl.cpp @@ -6841,8 +6841,16 @@ // OpenCL v2.0 s6.9.q: // The clk_event_t and reserve_id_t types cannot be declared in program // scope. + // OpenCL v2.0 s6.5.1: + // Variables defined at program scope and static variables inside a function + // can also be declared in the global address space. They can be defined with + // any valid OpenCL C data type except for those in Other Built-in Data Types. + // OpenCL v3.0 s6.11.w: + // Program scope variables can be defined with any valid OpenCL C data type + // except for those in Other Built-in Data Types. if (NewVD->hasGlobalStorage() && !NewVD->isStaticLocal()) { -if (R->isReserveIDT() || R->isClkEventT() || R->isEventT()) { +if (R->isReserveIDT() || R->isClkEventT() || R->isEventT() || +R.getUnqualifiedType().getAsString() == "ndrange_t" || R->isQueueT()) { Se.Diag(NewVD->getLocation(), diag::err_invalid_type_for_program_scope_var) << R; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D112110: [OpenCL] queue_t and ndrange_t can't be defined in program scope.
cycheng updated this revision to Diff 382816. cycheng added a comment. previous update was using wrong file, sorry!! CHANGES SINCE LAST ACTION https://reviews.llvm.org/D112110/new/ https://reviews.llvm.org/D112110 Files: clang/lib/Sema/SemaDecl.cpp clang/test/SemaOpenCL/invalid-types.cl Index: clang/test/SemaOpenCL/invalid-types.cl === --- /dev/null +++ clang/test/SemaOpenCL/invalid-types.cl @@ -0,0 +1,11 @@ +// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL2.0 +// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL3.0 -cl-ext=+__opencl_c_device_enqueue + +// Test declare "Other Data Type" variables in program scope. +global queue_t qt; // expected-error {{the '__global queue_t' type cannot be used to declare a program scope variable}} + +typedef struct {int a;} ndrange_t; +global ndrange_t qt; // expected-error {{the '__global ndrange_t' type cannot be used to declare a program scope variable}} + +typedef image2d_t test; +global test qtt; // expected-error {{the '__global ndrange_t' type cannot be used to declare a program scope variable}} Index: clang/lib/Sema/SemaDecl.cpp === --- clang/lib/Sema/SemaDecl.cpp +++ clang/lib/Sema/SemaDecl.cpp @@ -6841,8 +6841,12 @@ // OpenCL v2.0 s6.9.q: // The clk_event_t and reserve_id_t types cannot be declared in program // scope. + // OpenCL v3.0 s6.11.w: + // Program scope variables can be defined with any valid OpenCL C data type + // except for those in Other Built-in Data Types. if (NewVD->hasGlobalStorage() && !NewVD->isStaticLocal()) { -if (R->isReserveIDT() || R->isClkEventT() || R->isEventT()) { +if (R->isReserveIDT() || R->isClkEventT() || R->isEventT() || +R->isQueueT() || R.getUnqualifiedType().getAsString() == "ndrange_t") { Se.Diag(NewVD->getLocation(), diag::err_invalid_type_for_program_scope_var) << R; Index: clang/test/SemaOpenCL/invalid-types.cl === --- /dev/null +++ clang/test/SemaOpenCL/invalid-types.cl @@ -0,0 +1,11 @@ +// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL2.0 +// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL3.0 -cl-ext=+__opencl_c_device_enqueue + +// Test declare "Other Data Type" variables in program scope. +global queue_t qt; // expected-error {{the '__global queue_t' type cannot be used to declare a program scope variable}} + +typedef struct {int a;} ndrange_t; +global ndrange_t qt; // expected-error {{the '__global ndrange_t' type cannot be used to declare a program scope variable}} + +typedef image2d_t test; +global test qtt; // expected-error {{the '__global ndrange_t' type cannot be used to declare a program scope variable}} Index: clang/lib/Sema/SemaDecl.cpp === --- clang/lib/Sema/SemaDecl.cpp +++ clang/lib/Sema/SemaDecl.cpp @@ -6841,8 +6841,12 @@ // OpenCL v2.0 s6.9.q: // The clk_event_t and reserve_id_t types cannot be declared in program // scope. + // OpenCL v3.0 s6.11.w: + // Program scope variables can be defined with any valid OpenCL C data type + // except for those in Other Built-in Data Types. if (NewVD->hasGlobalStorage() && !NewVD->isStaticLocal()) { -if (R->isReserveIDT() || R->isClkEventT() || R->isEventT()) { +if (R->isReserveIDT() || R->isClkEventT() || R->isEventT() || +R->isQueueT() || R.getUnqualifiedType().getAsString() == "ndrange_t") { Se.Diag(NewVD->getLocation(), diag::err_invalid_type_for_program_scope_var) << R; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D112110: [OpenCL] queue_t and ndrange_t can't be defined in program scope.
cycheng added inline comments. Comment at: clang/lib/Sema/SemaDecl.cpp:6853 +if (R->isReserveIDT() || R->isClkEventT() || R->isEventT() || +R.getUnqualifiedType().getAsString() == "ndrange_t" || R->isQueueT()) { Se.Diag(NewVD->getLocation(), Anastasia wrote: > Suggest swapping those as string comparisons are more costly. > > However, does it work if there is a typedef of `ndrange_t` to some other > name? Although it feels like the same issue might apply to other types > diagnosed here... > does it work if there is a typedef of ndrange_t to some other name? No, should we recursively check it? Or do we have better way to handle this? Comment at: clang/test/SemaOpenCL/invalid-types.cl:5 +// Test declare "Other Data Type" variables in program scope. +global queue_t qt; // expected-error {{the '__global queue_t' type cannot be used to declare a program scope variable}} + Anastasia wrote: > if you create a type alias through typedef for `queue_t` or `ndrange_t`, will > you still get the diagnostic? > Sorry for late reply! No, I didn't catch that case, I am not sure how to handle this? Could you point out some code for reference? Comment at: clang/test/SemaOpenCL/invalid-types.cl:10 + +typedef image2d_t test; +global test qtt; // expected-error {{the '__global ndrange_t' type cannot be used to declare a program scope variable}} Anastasia wrote: > Did you mean to use `ndrange_t` or `queue_t` here? Otherwise, it doesn't seem > that your commit is related to the image types... Ah... sorry it's an accident. I will remove it. CHANGES SINCE LAST ACTION https://reviews.llvm.org/D112110/new/ https://reviews.llvm.org/D112110 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D112110: [OpenCL] queue_t and ndrange_t can't be defined in program scope.
cycheng created this revision. cycheng added a reviewer: Anastasia. Herald added subscribers: ldrumm, yaxunl. cycheng requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits. OpenCL v2.0 s6.5.1 and OpenCL v3.0 s6.11.w both state: Program scope variables can be defined with any valid OpenCL C data type except for those in Other Built-in Data Types. This patch adds the required check in diagnoseOpenCLTypes. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D112110 Files: clang/lib/Sema/SemaDecl.cpp clang/test/SemaOpenCL/invalid-ndrange.cl clang/test/SemaOpenCL/invalid-queue.cl Index: clang/test/SemaOpenCL/invalid-queue.cl === --- /dev/null +++ clang/test/SemaOpenCL/invalid-queue.cl @@ -0,0 +1,4 @@ +// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL2.0 +// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL3.0 -cl-ext=+__opencl_c_device_enqueue + +global queue_t qt; // expected-error {{the '__global queue_t' type cannot be used to declare a program scope variable}} Index: clang/test/SemaOpenCL/invalid-ndrange.cl === --- /dev/null +++ clang/test/SemaOpenCL/invalid-ndrange.cl @@ -0,0 +1,6 @@ +// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL2.0 +// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL3.0 + +typedef struct {int a;} ndrange_t; + +global ndrange_t qt; // expected-error {{the '__global ndrange_t' type cannot be used to declare a program scope variable}} Index: clang/lib/Sema/SemaDecl.cpp === --- clang/lib/Sema/SemaDecl.cpp +++ clang/lib/Sema/SemaDecl.cpp @@ -6841,8 +6841,16 @@ // OpenCL v2.0 s6.9.q: // The clk_event_t and reserve_id_t types cannot be declared in program // scope. + // OpenCL v2.0 s6.5.1: + // Variables defined at program scope and static variables inside a function + // can also be declared in the global address space. They can be defined with + // any valid OpenCL C data type except for those in Other Built-in Data Types. + // OpenCL v3.0 s6.11.w: + // Program scope variables can be defined with any valid OpenCL C data type + // except for those in Other Built-in Data Types. if (NewVD->hasGlobalStorage() && !NewVD->isStaticLocal()) { -if (R->isReserveIDT() || R->isClkEventT() || R->isEventT()) { +if (R->isReserveIDT() || R->isClkEventT() || R->isEventT() || +R.getUnqualifiedType().getAsString() == "ndrange_t" || R->isQueueT()) { Se.Diag(NewVD->getLocation(), diag::err_invalid_type_for_program_scope_var) << R; Index: clang/test/SemaOpenCL/invalid-queue.cl === --- /dev/null +++ clang/test/SemaOpenCL/invalid-queue.cl @@ -0,0 +1,4 @@ +// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL2.0 +// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL3.0 -cl-ext=+__opencl_c_device_enqueue + +global queue_t qt; // expected-error {{the '__global queue_t' type cannot be used to declare a program scope variable}} Index: clang/test/SemaOpenCL/invalid-ndrange.cl === --- /dev/null +++ clang/test/SemaOpenCL/invalid-ndrange.cl @@ -0,0 +1,6 @@ +// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL2.0 +// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL3.0 + +typedef struct {int a;} ndrange_t; + +global ndrange_t qt; // expected-error {{the '__global ndrange_t' type cannot be used to declare a program scope variable}} Index: clang/lib/Sema/SemaDecl.cpp === --- clang/lib/Sema/SemaDecl.cpp +++ clang/lib/Sema/SemaDecl.cpp @@ -6841,8 +6841,16 @@ // OpenCL v2.0 s6.9.q: // The clk_event_t and reserve_id_t types cannot be declared in program // scope. + // OpenCL v2.0 s6.5.1: + // Variables defined at program scope and static variables inside a function + // can also be declared in the global address space. They can be defined with + // any valid OpenCL C data type except for those in Other Built-in Data Types. + // OpenCL v3.0 s6.11.w: + // Program scope variables can be defined with any valid OpenCL C data type + // except for those in Other Built-in Data Types. if (NewVD->hasGlobalStorage() && !NewVD->isStaticLocal()) { -if (R->isReserveIDT() || R->isClkEventT() || R->isEventT()) { +if (R->isReserveIDT() || R->isClkEventT() || R->isEventT() || +R.getUnqualifiedType().getAsString() == "ndrange_t" || R->isQueueT()) { Se.Diag(NewVD->getLocation(), diag::err_invalid_type_for_program_scope_var) << R; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-