This revision was landed with ongoing or failed builds. This revision was automatically updated to reflect the committed changes. Closed by commit rG237c6924bd46: [OpenCL] Add clang extension for bit-fields. (authored by Anastasia). Herald added subscribers: foad, ldrumm. Herald added a project: clang.
Changed prior to commit: https://reviews.llvm.org/D101843?vs=344784&id=347348#toc Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D101843/new/ https://reviews.llvm.org/D101843 Files: clang/docs/LanguageExtensions.rst clang/include/clang/Basic/OpenCLExtensions.def clang/lib/Basic/Targets/AMDGPU.h clang/lib/Basic/Targets/NVPTX.h clang/lib/Sema/SemaDecl.cpp clang/test/Misc/amdgcn.languageOptsOpenCL.cl clang/test/Misc/nvptx.languageOptsOpenCL.cl clang/test/Misc/r600.languageOptsOpenCL.cl clang/test/SemaOpenCL/unsupported.cl
Index: clang/test/SemaOpenCL/unsupported.cl =================================================================== --- clang/test/SemaOpenCL/unsupported.cl +++ clang/test/SemaOpenCL/unsupported.cl @@ -1,7 +1,15 @@ // RUN: %clang_cc1 -verify %s +// RUN: %clang_cc1 -verify %s -DBITFIELDS_EXT -struct { - int a : 1; // expected-error {{bit-fields are not supported in OpenCL}} +#ifdef BITFIELDS_EXT +#pragma OPENCL EXTENSION __cl_clang_bitfields : enable +#endif + +struct test { + int a : 1; +#ifndef BITFIELDS_EXT +// expected-error@-2 {{bit-fields are not supported in OpenCL}} +#endif }; void no_vla(int n) { Index: clang/test/Misc/r600.languageOptsOpenCL.cl =================================================================== --- clang/test/Misc/r600.languageOptsOpenCL.cl +++ clang/test/Misc/r600.languageOptsOpenCL.cl @@ -39,6 +39,11 @@ #endif #pragma OPENCL EXTENSION __cl_clang_non_portable_kernel_param_types : enable +#ifndef __cl_clang_bitfields +#error "Missing __cl_clang_bitfields define" +#endif +#pragma OPENCL EXTENSION __cl_clang_bitfields : enable + #ifdef cl_khr_fp16 #error "Incorrect cl_khr_fp16 define" #endif Index: clang/test/Misc/nvptx.languageOptsOpenCL.cl =================================================================== --- clang/test/Misc/nvptx.languageOptsOpenCL.cl +++ clang/test/Misc/nvptx.languageOptsOpenCL.cl @@ -33,6 +33,11 @@ #endif #pragma OPENCL EXTENSION __cl_clang_non_portable_kernel_param_types : enable +#ifndef __cl_clang_bitfields +#error "Missing __cl_clang_bitfields define" +#endif +#pragma OPENCL EXTENSION __cl_clang_bitfields : enable + #ifdef cl_khr_fp16 #error "Incorrect cl_khr_fp16 define" #endif Index: clang/test/Misc/amdgcn.languageOptsOpenCL.cl =================================================================== --- clang/test/Misc/amdgcn.languageOptsOpenCL.cl +++ clang/test/Misc/amdgcn.languageOptsOpenCL.cl @@ -29,6 +29,11 @@ #endif #pragma OPENCL EXTENSION __cl_clang_non_portable_kernel_param_types : enable +#ifndef __cl_clang_bitfields +#error "Missing __cl_clang_bitfields define" +#endif +#pragma OPENCL EXTENSION __cl_clang_bitfields : enable + #ifndef cl_khr_fp16 #error "Missing cl_khr_fp16 define" #endif Index: clang/lib/Sema/SemaDecl.cpp =================================================================== --- clang/lib/Sema/SemaDecl.cpp +++ clang/lib/Sema/SemaDecl.cpp @@ -16815,8 +16815,10 @@ Record->setInvalidDecl(); InvalidDecl = true; } - // OpenCL v1.2 s6.9.c: bitfields are not supported. - if (BitWidth) { + // OpenCL v1.2 s6.9.c: bitfields are not supported, unless Clang extension + // is enabled. + if (BitWidth && !getOpenCLOptions().isAvailableOption( + "__cl_clang_bitfields", LangOpts)) { Diag(Loc, diag::err_opencl_bitfields); InvalidDecl = true; } Index: clang/lib/Basic/Targets/NVPTX.h =================================================================== --- clang/lib/Basic/Targets/NVPTX.h +++ clang/lib/Basic/Targets/NVPTX.h @@ -136,6 +136,7 @@ Opts["__cl_clang_function_pointers"] = true; Opts["__cl_clang_variadic_functions"] = true; Opts["__cl_clang_non_portable_kernel_param_types"] = true; + Opts["__cl_clang_bitfields"] = true; Opts["cl_khr_fp64"] = true; Opts["__opencl_c_fp64"] = true; Index: clang/lib/Basic/Targets/AMDGPU.h =================================================================== --- clang/lib/Basic/Targets/AMDGPU.h +++ clang/lib/Basic/Targets/AMDGPU.h @@ -288,6 +288,7 @@ Opts["__cl_clang_variadic_functions"] = true; Opts["__cl_clang_function_pointers"] = true; Opts["__cl_clang_non_portable_kernel_param_types"] = true; + Opts["__cl_clang_bitfields"] = true; bool IsAMDGCN = isAMDGCN(getTriple()); Index: clang/include/clang/Basic/OpenCLExtensions.def =================================================================== --- clang/include/clang/Basic/OpenCLExtensions.def +++ clang/include/clang/Basic/OpenCLExtensions.def @@ -88,6 +88,7 @@ OPENCL_EXTENSION(__cl_clang_function_pointers, true, 100) OPENCL_EXTENSION(__cl_clang_variadic_functions, true, 100) OPENCL_EXTENSION(__cl_clang_non_portable_kernel_param_types, true, 100) +OPENCL_EXTENSION(__cl_clang_bitfields, true, 100) // AMD OpenCL extensions OPENCL_EXTENSION(cl_amd_media_ops, true, 100) Index: clang/docs/LanguageExtensions.rst =================================================================== --- clang/docs/LanguageExtensions.rst +++ clang/docs/LanguageExtensions.rst @@ -1741,6 +1741,34 @@ Clang supports internal OpenCL extensions documented below. +``__cl_clang_bitfields`` +-------------------------------- + +With this extension it is possible to enable bitfields in structs +or unions using the OpenCL extension pragma mechanism detailed in +`the OpenCL Extension Specification, section 1.2 +<https://www.khronos.org/registry/OpenCL/specs/3.0-unified/html/OpenCL_Ext.html#extensions-overview>`_. + +Use of bitfields in OpenCL kernels can result in reduced portability as struct +layout is not guaranteed to be consistent when compiled by different compilers. +If structs with bitfields are used as kernel function parameters, it can result +in incorrect functionality when the layout is different between the host and +device code. + +**Example of Use**: + +.. code-block:: c++ + + #pragma OPENCL EXTENSION __cl_clang_bitfields : enable + struct with_bitfield { + unsigned int i : 5; // compiled - no diagnostic generated + }; + + #pragma OPENCL EXTENSION __cl_clang_bitfields : disable + struct without_bitfield { + unsigned int i : 5; // error - bitfields are not supported + }; + ``__cl_clang_function_pointers`` --------------------------------
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits