[PATCH] D120254: [OpenCL] Align subgroup builtin guards

Sven van Haastregt via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Mar 31 07:15:10 PDT 2022


svenvh added a comment.

In D120254#3419221 <https://reviews.llvm.org/D120254#3419221>, @hvdijk wrote:

> This was worked around by modifying tests, but I believe this is a fundamental problem in this change and was able to reproduce the error with plain old clang:
>
>   $ cat test.cl
>   void sub_group_barrier();
>   
>   $ bin/clang -cl-std=CL1.2 -S -o - test.cl
>   error: enum type memory_scope not found; include the base header with -finclude-default-header
>   1 error generated.
>   
>   $ bin/clang --version
>   clang version 15.0.0 (git at github.com:llvm/llvm-project c204cee642ee794901d2e8a9819b52ac12f92bc9)
>   Target: x86_64-unknown-linux-gnu
>   Thread model: posix
>   InstalledDir: /home/harald/llvm-project/build/bin
>
> The problem is that this change enables certain built-ins in OpenCL 1.2 that take a memory_scope argument, but the memory_scope type is not defined in OpenCL 1.2 mode. When we then process the function, sub_group_barrier in my example, things break when checking whether the declaration matches the built-in. I am not sure what the right fix here is. Can we just define the type if any extension is enabled that requires the type, or is that not allowed?

Thanks for digging further and providing a reproducer!  I think the fix is to only make the `sub_group_barrier(cl_mem_fence_flags flags, memory_scope)` overload available for OpenCL 2.0 or above.  That would also match `opencl-c.h`.

The following patch seems to fix the issue that you described:

  diff --git a/clang/lib/Sema/OpenCLBuiltins.td b/clang/lib/Sema/OpenCLBuiltins.td
  index f6de59223347..52740bacac33 100644
  --- a/clang/lib/Sema/OpenCLBuiltins.td
  +++ b/clang/lib/Sema/OpenCLBuiltins.td
  @@ -1692,7 +1692,9 @@ let Extension = FuncExtKhrSubgroups in {
   // --- Table 28.2.2 ---
   let Extension = FuncExtKhrSubgroups in {
     def : Builtin<"sub_group_barrier", [Void, MemFenceFlags], Attr.Convergent>;
  -  def : Builtin<"sub_group_barrier", [Void, MemFenceFlags, MemoryScope], Attr.Convergent>;
  +  let MinVersion = CL20 in {
  +    def : Builtin<"sub_group_barrier", [Void, MemFenceFlags, MemoryScope], Attr.Convergent>;
  +  }
   }
   
   // --- Table 28.2.4 ---


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D120254/new/

https://reviews.llvm.org/D120254



More information about the cfe-commits mailing list