This is an archive of the discontinued LLVM Phabricator instance.

[OpenCL] Add clang extension for bitfields
ClosedPublic

Authored by Anastasia on May 4 2021, 9:23 AM.

Details

Summary

Bitfields result in struct/union layout that is implementation dependent and therefore it was excluded from OpenCL originally for portability reasons. In kernel prameters use of bitfields can result in functionality issues.

However, use of bitfields has been desirable feature for some applications, there was a discussion about allowing this in the next standards (https://github.com/KhronosGroup/OpenCL-Docs/issues/301) but regardless to that clang can expose this functionality as a compiler extension for the application that can take advanatge of it at the price of reduced portability.

This addresses PR45339!

Diff Detail

Event Timeline

Anastasia created this revision.May 4 2021, 9:23 AM
Anastasia requested review of this revision.May 4 2021, 9:23 AM
kpet added a subscriber: kpet.May 4 2021, 10:52 AM
svenvh added inline comments.May 6 2021, 8:41 AM
clang/docs/LanguageExtensions.rst
1748
clang/lib/Sema/SemaDecl.cpp
16817–16818
clang/test/SemaOpenCL/unsupported.cl
11

The extension has "bitfields" in the name but most diagnostics (including this one) spell it as "bit-fields". I wonder what the least surprising name would be? It seems Clang tends to use the hyphenated form in diagnostics and the non-hyphenated form in e.g. option names (e.g. fsigned-bitfields), so using the non-hyphenated form in the extension name is probably fine.

Anastasia added inline comments.May 7 2021, 7:17 AM
clang/test/SemaOpenCL/unsupported.cl
11

Hyphenated words are often split so we could also go for __cl_clang_bit_fields? But I think this might be more confusing...

Anastasia updated this revision to Diff 344784.May 12 2021, 5:42 AM

Added suggestions from Sven.

Anastasia added inline comments.May 12 2021, 5:43 AM
clang/lib/Sema/SemaDecl.cpp
16817–16818

Slightly modified to avoid repeating the extension name that can be read from the source code.

svenvh accepted this revision.May 21 2021, 6:58 AM

LGTM!

This revision is now accepted and ready to land.May 21 2021, 6:58 AM
This revision was landed with ongoing or failed builds.May 24 2021, 4:42 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptMay 24 2021, 4:42 AM
Herald added subscribers: foad, ldrumm. · View Herald Transcript