Skip to content

[clang][SYCL] Fix integration header for free function kernels with enum values in args#21278

Open
dklochkov-emb wants to merge 7 commits intosyclfrom
sycl-free-function-enum-issue
Open

[clang][SYCL] Fix integration header for free function kernels with enum values in args#21278
dklochkov-emb wants to merge 7 commits intosyclfrom
sycl-free-function-enum-issue

Conversation

@dklochkov-emb
Copy link
Contributor

This pull request fixes the problem of using enum value names with free functions.
Context of the problem:
Free function kernels use integration header to create shim functions. It is added forward declarations for this. I.e. if we have some free function kernel:

void some_kernel_func(some_args){
...
}

Wee need to emit its declaration into integration header because user sources are not "available" from header:
void some_kernel_func(some_args);

However, if any of arguments(some_args) are classes, structs etc we need to emit their forward declarations
Using enum does not produce problems but using enum value names emits build error because compiler does not allow to use forward declaration of particular enum value, i.e.

enum class A{
A0.
A1
};

it is not allowed to use forward declaration of A::A0

This pull request adds workaround solution of the problem: every enum value name is replaced with its value casted to enum type during sema analysis. I.e.
A::A1 is replaced with static_cast<A>(1);

@Fznamznon Fznamznon changed the title Sycl free function enum issue ifx [clang][SYCL] Fix integration header for free function kernels with enum values in args Feb 13, 2026
Copy link
Contributor

@Fznamznon Fznamznon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm just curious about what it will print for something like

enum class A : int {
  B,
  C
};

template <A a, typename B> struct C{

};

void freefunctionkernel(C<static_cast<A>(38), int> cc);

[SYCL] decrease small string size
@dklochkov-emb
Copy link
Contributor Author

dklochkov-emb commented Feb 13, 2026

I'm just curious about what it will print for something like

enum class A : int {
  B,
  C
};

template <A a, typename B> struct C{

};

void freefunctionkernel(C<static_cast<A>(38), int> cc);

Integration header will contain something like this:
`
enum class A : int;
template <A a, typename B> struct C;

void freefunctionkernel(C<static_cast(38), int> cc);
static constexpr auto __sycl_shim() {
return (void (*)(struct C<static_cast(38), int>))freefunctionkernel;
}
`

@Fznamznon
Copy link
Contributor

static_cast(38) won't compile right? What if the value is within the range of enum values?

@dklochkov-emb
Copy link
Contributor Author

dklochkov-emb commented Feb 16, 2026

static_cast(38) won't compile right? What if the value is within the range of enum values?

I did not manage to compile with this example both cases - within the range and out of it:
void freefunctionkernel(C<static_cast<A>(38), int> cc);

However, when I set something easier and closer to bugs:
at::native::xpu::OpSFunctor<int, static_cast<at::native::xpu::OP_MODE_SCOPED>(2)> at::native::xpu::OpSFunctor<int, static_cast<at::native::xpu::OP_MODE_SCOPED>(32)>
It is compiled without errors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants