<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Hi CY,</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Indeed, this seems like a bug. Feel free to submit a bug report or upload the review for your patch straight away.</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Thanks,</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Anastasia<br>
</div>
<div id="appendonsend"></div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<hr tabindex="-1" style="display:inline-block; width:98%">
<div id="divRplyFwdMsg" dir="ltr"><font style="font-size:11pt" face="Calibri, sans-serif" color="#000000"><b>From:</b> cfe-dev <cfe-dev-bounces@lists.llvm.org> on behalf of Chuang-Yu Cheng via cfe-dev <cfe-dev@lists.llvm.org><br>
<b>Sent:</b> 18 October 2021 11:00<br>
<b>To:</b> cfe-dev@lists.llvm.org <cfe-dev@lists.llvm.org><br>
<b>Subject:</b> [cfe-dev] [OpenCL2.x] Declare/Define “Other Data Types” with global address space in program scope</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt">
<div class="PlainText">Hi,<br>
<br>
In OpenCL2.x, I think it is not legal to declare/define “Other Data<br>
Types” ndrange_t / queue_t / … etc, with global address space in<br>
program scope, for example:<br>
<br>
test.cl<br>
```c<br>
global ndrange_t nrt;<br>
global queue_t qt;<br>
<br>
kernel void test(global int *a) { a[0] = 0; }<br>
```<br>
<br>
Given the OpenCL2.x spec states:<br>
<a href="https://www.khronos.org/registry/OpenCL/specs/2.2/html/OpenCL_C.html">https://www.khronos.org/registry/OpenCL/specs/2.2/html/OpenCL_C.html</a><br>
<br>
In 6.5.1. __global (or global):<br>
“Variables defined at program scope and static variables inside a<br>
function can also be declared in the global address space. They can be<br>
defined with any valid OpenCL C data type except for those in Other<br>
Built-in Data Types. In particular, such program scope variables may<br>
be of any user-defined type, or a pointer to a user-defined type.”<br>
<br>
But I use clang-13 to compile the test case, it passes without any<br>
warning or error:<br>
<br>
clang-13 --target=amdgcn -cl-std=CL2.0 -S -O3 test.cl<br>
<br>
Should we add more checks in: clang/lib/Sema/SemaDecl.cpp<br>
<br>
/// Returns true if there hasn't been any invalid type diagnosed.<br>
static bool diagnoseOpenCLTypes(Scope *S, Sema &Se, Declarator &D,<br>
                                DeclContext *DC, QualType R) {<br>
  ...<br>
<br>
  // OpenCL v1.2 s6.9.r:<br>
  // The event type cannot be used to declare a program scope variable.<br>
  // OpenCL v2.0 s6.9.q:<br>
  // The clk_event_t and reserve_id_t types cannot be declared in program<br>
  // scope.<br>
  if (NULL == S->getParent()) {<br>
-    if (R->isReserveIDT() || R->isClkEventT() || R->isEventT()) {<br>
+    if (R->isReserveIDT() || R->isClkEventT() || R->isEventT() ||<br>
+       R.getUnqualifiedType().getAsString() == "ndrange_t" ||<br>
+      R->isQueueT()) {<br>
      Se.Diag(D.getIdentifierLoc(),<br>
              diag::err_invalid_type_for_program_scope_var)<br>
          << R;<br>
      D.setInvalidType();<br>
      return false;<br>
    }<br>
  }<br>
<br>
Thanks,<br>
CY<br>
_______________________________________________<br>
cfe-dev mailing list<br>
cfe-dev@lists.llvm.org<br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev">https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br>
</div>
</span></font></div>
</body>
</html>