Clang error: attribute A can only be applied to an OpenCL kernel function (err_opencl_kernel_attr)
Jump to navigation
Jump to search
Text | error: attribute A can only be applied to an OpenCL kernel function (since 7.0) error: attribute A can only be applied to a kernel function (until 6.0) |
---|---|
Type | Error |
Category | Semantic Issue |
Internal Id | err_opencl_kernel_attr |
Internal Message | attribute %0 can only be applied to an OpenCL kernel function (since 7.0)attribute %0 can only be applied to a kernel function (until 6.0)
|
Regular Expression | (?:error|fatal error)\: attribute (.*?) can only be applied to an OpenCL kernel function
|
First Commit | 2013-12-13 2cd9db1cefbb [OpenCL] Produce an error when the work group and vec type hint attributes |
Description
Example
Flags | -xcl -cl-std=CL1.2
|
|
---|---|---|
Source |
__attribute__((vec_type_hint(float))) void f() {}
// Applied vec_type_hint to a non-kernel function.
| |
Compiler Output |
<source>:1:44: error: attribute 'vec_type_hint' can only be applied to an OpenCL kernel function |
Clang Internals (17.0.6)
Git Commit Message
[OpenCL] Produce an error when the work group and vec type hint attributes are used on non-kernel functions. Reviewed by Aaron over IRC! llvm-svn: 197243
Used in Clang Sources
This section lists all occurrences of the diagnostic within the Clang's codebase. For each occurrence, an auto-extracted snipped from the source code is listed including key elements like control structures, functions, or classes. It should illustrate the conditions under which the diagnostic is activated.
clang/lib/Sema/SemaDeclAttr.cpp (line 9530)
/// ProcessDeclAttributeList - Apply all the decl attributes in the specified
/// attribute list to the specified decl, ignoring any type attributes.
void Sema::ProcessDeclAttributeList(Scope *S, Decl *D, const ParsedAttributesView &AttrList, const ProcessDeclAttributeOptions &Options) {
// ...
// FIXME: We should be able to handle this in TableGen as well. It would be
// good to have a way to specify "these attributes must appear as a group",
// for these. Additionally, it would be good to have a way to specify "these
// attribute must never appear as a group" for attributes like cold and hot.
if (!D->hasAttr<OpenCLKernelAttr>()) {
// These attributes cannot be applied to a non-kernel function.
if (const auto *A = D->getAttr<ReqdWorkGroupSizeAttr>()) {
// ...
Diag(D->getLocation(), diag::err_opencl_kernel_attr) << A;
clang/lib/Sema/SemaDeclAttr.cpp (line 9533)
/// ProcessDeclAttributeList - Apply all the decl attributes in the specified
/// attribute list to the specified decl, ignoring any type attributes.
void Sema::ProcessDeclAttributeList(Scope *S, Decl *D, const ParsedAttributesView &AttrList, const ProcessDeclAttributeOptions &Options) {
// ...
// FIXME: We should be able to handle this in TableGen as well. It would be
// good to have a way to specify "these attributes must appear as a group",
// for these. Additionally, it would be good to have a way to specify "these
// attribute must never appear as a group" for attributes like cold and hot.
if (!D->hasAttr<OpenCLKernelAttr>()) {
// These attributes cannot be applied to a non-kernel function.
if (const auto *A = D->getAttr<ReqdWorkGroupSizeAttr>()) {
// ...
} else if (const auto *A = D->getAttr<WorkGroupSizeHintAttr>()) {
Diag(D->getLocation(), diag::err_opencl_kernel_attr) << A;
clang/lib/Sema/SemaDeclAttr.cpp (line 9536)
/// ProcessDeclAttributeList - Apply all the decl attributes in the specified
/// attribute list to the specified decl, ignoring any type attributes.
void Sema::ProcessDeclAttributeList(Scope *S, Decl *D, const ParsedAttributesView &AttrList, const ProcessDeclAttributeOptions &Options) {
// ...
// FIXME: We should be able to handle this in TableGen as well. It would be
// good to have a way to specify "these attributes must appear as a group",
// for these. Additionally, it would be good to have a way to specify "these
// attribute must never appear as a group" for attributes like cold and hot.
if (!D->hasAttr<OpenCLKernelAttr>()) {
// These attributes cannot be applied to a non-kernel function.
if (const auto *A = D->getAttr<ReqdWorkGroupSizeAttr>()) {
// ...
} else if (const auto *A = D->getAttr<WorkGroupSizeHintAttr>()) {
// ...
} else if (const auto *A = D->getAttr<VecTypeHintAttr>()) {
Diag(D->getLocation(), diag::err_opencl_kernel_attr) << A;
clang/lib/Sema/SemaDeclAttr.cpp (line 9539)
/// ProcessDeclAttributeList - Apply all the decl attributes in the specified
/// attribute list to the specified decl, ignoring any type attributes.
void Sema::ProcessDeclAttributeList(Scope *S, Decl *D, const ParsedAttributesView &AttrList, const ProcessDeclAttributeOptions &Options) {
// ...
// FIXME: We should be able to handle this in TableGen as well. It would be
// good to have a way to specify "these attributes must appear as a group",
// for these. Additionally, it would be good to have a way to specify "these
// attribute must never appear as a group" for attributes like cold and hot.
if (!D->hasAttr<OpenCLKernelAttr>()) {
// These attributes cannot be applied to a non-kernel function.
if (const auto *A = D->getAttr<ReqdWorkGroupSizeAttr>()) {
// ...
} else if (const auto *A = D->getAttr<WorkGroupSizeHintAttr>()) {
// ...
} else if (const auto *A = D->getAttr<VecTypeHintAttr>()) {
// ...
} else if (const auto *A = D->getAttr<OpenCLIntelReqdSubGroupSizeAttr>()) {
Diag(D->getLocation(), diag::err_opencl_kernel_attr) << A;
Triggered in Clang Tests
This section lists all internal Clang test cases that trigger the diagnostic.
clang/test/SemaCUDA/amdgpu-attrs.cu
- clang/test/SemaCUDA/amdgpu-attrs.cu:68:17: error: attribute 'reqd_work_group_size' can only be applied to an OpenCL kernel function
- clang/test/SemaCUDA/amdgpu-attrs.cu:72:17: error: attribute 'work_group_size_hint' can only be applied to an OpenCL kernel function
- clang/test/SemaCUDA/amdgpu-attrs.cu:76:17: error: attribute 'vec_type_hint' can only be applied to an OpenCL kernel function
- clang/test/SemaCUDA/amdgpu-attrs.cu:80:17: error: attribute 'intel_reqd_sub_group_size' can only be applied to an OpenCL kernel function