llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.13k stars 11.62k forks source link

Not all OpenCL extensions are disabled by default #47226

Open llvmbot opened 3 years ago

llvmbot commented 3 years ago
Bugzilla Link 47882
Version unspecified
OS Linux
Reporter LLVM Bugzilla Contributor
CC @AnastasiaStulova

Extended Description

The OpenCL specification requires implementation to disable all extensions by default. This implies that using any builtin functions from an extension should produce a compile-time error.

Clang doesn't respect this rules, at least not for all extensions as the following example shows:

unsigned int foo() { return get_sub_group_size(); }

This code compiles (while it should not) when using opencl-c.h and doesn't (as expected) when using -fdeclare-opencl-builtins.

https://godbolt.org/z/WrMsMj

For reference, see the specification https://www.khronos.org/registry/OpenCL/specs/3.0-unified/html/OpenCL_Ext.html#compiler-directives-for-optional-extensions

llvmbot commented 3 years ago

For OpenCL 1.0, the following extensions do no require pragma directive when they should according to the spec:

llvmbot commented 3 years ago

I looked at the values returned by clang::OpenCLOptions::isEnabled for each extension supported by Clang and found out that:

Furthermore, for the following extensions Clang does not require a #pragma directive when it should (i.e. BIFs/types are available/usable by default):

I'm not sure how cl_khr_srgb_image_writes should behave and therefore be tested.