Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions clang/lib/Sema/SemaSYCL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6822,13 +6822,13 @@ class FreeFunctionPrinter {
continue;
}

TemplateName TN = TST->getTemplateName();
TemplateName CTN = CTST->getTemplateName();
CTN.getAsTemplateDecl()->printQualifiedName(ParmListOstream);
ParmListOstream << "<";

auto SpecArgs = TST->template_arguments();
auto DeclArgs = CTST->template_arguments();

TN.getAsTemplateDecl()->printQualifiedName(ParmListOstream);
ParmListOstream << "<";

for (size_t I = 0, E = std::max(DeclArgs.size(), SpecArgs.size()),
SE = SpecArgs.size();
I < E; ++I) {
Expand Down
63 changes: 63 additions & 0 deletions clang/test/CodeGenSYCL/free-function-kernel-type-alias-arg.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// RUN: %clang_cc1 -fsycl-is-device -internal-isystem %S/Inputs -triple spir64-unknown-unknown -sycl-std=2020 -fsycl-int-header=%t.h %s
// RUN: FileCheck -input-file=%t.h %s
//
// The purpose of this test is to ensure that forward declarations of free
// function kernels are emitted properly.
// However, this test checks a specific scenario:
// - free function arguments are type aliases (through using or typedef)

namespace ns {

using IntUsing = int;
typedef int IntTypedef;

template <typename T>
struct Foo {};

using FooIntUsing = Foo<int>;
typedef Foo<int> FooIntTypedef;

template <typename T1, typename T2>
struct Bar {};

template<typename T1>
using BarUsing = Bar<T1, float>;

class Baz {
public:
using type = BarUsing<double>;
};

} // namespace ns

[[__sycl_detail__::add_ir_attributes_function("sycl-nd-range-kernel", 2)]]
void int_using(ns::IntUsing Arg) {}

// CHECK: void int_using(int Arg);

[[__sycl_detail__::add_ir_attributes_function("sycl-nd-range-kernel", 2)]]
void int_typedef(ns::IntTypedef Arg) {}

// CHECK: void int_typedef(int Arg);

[[__sycl_detail__::add_ir_attributes_function("sycl-nd-range-kernel", 2)]]
void foo_using(ns::FooIntUsing Arg) {}

// CHECK: void foo_using(ns::Foo<int> Arg);

[[__sycl_detail__::add_ir_attributes_function("sycl-nd-range-kernel", 2)]]
void foo_typedef(ns::FooIntTypedef Arg) {}

// CHECK: void foo_typedef(ns::Foo<int> Arg);

template<typename T>
[[__sycl_detail__::add_ir_attributes_function("sycl-nd-range-kernel", 2)]]
void bar_using(ns::BarUsing<T> Arg) {}
template void bar_using(ns::BarUsing<int>);
Copy link
Contributor

@Fznamznon Fznamznon Sep 18, 2025

Choose a reason for hiding this comment

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

Does something like

class A {
    public:
    using B = int;
};

void freefu(A::B a) {

}

work?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it works, I added it as a test case in e327133


// CHECK: template <typename T> void bar_using(ns::Bar<T, float>);

[[__sycl_detail__::add_ir_attributes_function("sycl-nd-range-kernel", 2)]]
void baz_type(ns::Baz::type Arg) {}

// CHECK: void baz_type(ns::Bar<double, float> Arg);
Loading