Clang error: array of A type is invalid in OpenCL (err_opencl_invalid_type_array)

From emmtrix Wiki
Jump to navigation Jump to search
Text error: array of A type is invalid in OpenCL
Type Error
Category Semantic Issue
Internal Id err_opencl_invalid_type_array
Internal Message array of %0 type is invalid in OpenCL
Regular Expression (?:error|fatal error)\: array of (.*?) type is invalid in OpenCL
First Commit 2016-02-24 89307aa3e9fc [OpenCL] Add Sema checks for OpenCL 2.0 block

Description

The error is issued by the Clang compiler when an attempt is made to define an array whose elements are of a type that is invalid within an OpenCL context. OpenCL, as a framework for writing programs that execute across heterogeneous platforms, imposes specific restrictions on the types that can be utilized in array declarations. In particular, the OpenCL specification delineates that arrays cannot consist of elements that are of block pointer, pipe, sampler, or image types. This limitation stems from the OpenCL specification’s intent to ensure compatibility and functionality across the diverse hardware and software platforms OpenCL targets. Thus, when the Clang compiler identifies an array declaration where the element type is among these restricted categories, it generates this error message to alert the developer to the violation of OpenCL's type constraints.  
AI Generated

Example

In the following example, a kernel function named f is defined, which attempts to utilize an array of image2d_t as a parameter. This attempt is showcased through the declaration of the function's parameter as __global image2d_t i[], where __global denotes a memory address space qualifier indicating that the images reside in the global address space. However, according to the specifications of OpenCL, arrays of certain types, including image and sampler types, are not supported. This restriction is in place due to the specification's goal to ensure compatibility and functionality across a wide range of hardware and software configurations. As a result, the Clang compiler recognizes this array declaration as a violation of the OpenCL restrictions regarding array element types and subsequently generates an error message to underscore this infringement.  
AI Generated


Flags -x cl -cl-std=CL1.2

[Try out in Compiler Explorer]

Source
__kernel void f(__global image2d_t i[]) {
  // Arrays of image2d_t are invalid
}
Compiler Output
<source>:1:37: error: array of '__global __read_only image2d_t' type is invalid in OpenCL


Clang Internals (17.0.6)

Git Commit Message

[OpenCL] Add Sema checks for OpenCL 2.0 block

Summary:
Add Sema checks for opencl 2.0 new features: Block.
This patch is partitioned from http://reviews.llvm.org/D16047

Reviewers: Anastasia

Subscribers: pekka.jaaskelainen, cfe-commits

Differential Revision: http://reviews.llvm.org/D17436

llvm-svn: 261719

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/SemaType.cpp (line 2691)

/// Build an array type.
///
/// \param T The type of each element in the array.
///
/// \param ASM C99 array size modifier (e.g., '*', 'static').
///
/// \param ArraySize Expression describing the size of the array.
///
/// \param Brackets The range from the opening '[' to the closing ']'.
///
/// \param Entity The name of the entity that involves the array
/// type, if known.
///
/// \returns A suitable array type, if there are no errors. Otherwise,
/// returns a NULL type.
QualType Sema::BuildArrayType(QualType T, ArrayType::ArraySizeModifier ASM, Expr *ArraySize, unsigned Quals, SourceRange Brackets, DeclarationName Entity) {
  // ...
  // OpenCL v2.0 s6.12.5 - Arrays of blocks are not supported.
  // OpenCL v2.0 s6.16.13.1 - Arrays of pipe type are not supported.
  // OpenCL v2.0 s6.9.b - Arrays of image/sampler type are not supported.
  if (getLangOpts().OpenCL) {
    // ...
    if (ArrType->isBlockPointerType() || ArrType->isPipeType() || ArrType->isSamplerT() || ArrType->isImageType()) {
      Diag(Loc, diag::err_opencl_invalid_type_array) << ArrType;

Triggered in Clang Tests

This section lists all internal Clang test cases that trigger the diagnostic.

clang/test/SemaOpenCL/invalid-block.cl

  • clang/test/SemaOpenCL/invalid-block.cl:65:12: error: array of 'bl2_t' (aka 'int (__generic ^const)(__private int)') type is invalid in OpenCL