Skip to content

[SYCL] Fix forward declaration in integration header #9087

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 25, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
12 changes: 8 additions & 4 deletions clang/include/clang/AST/PrettyPrinter.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,11 @@ struct PrintingPolicy {
ConstantArraySizeAsWritten(false), AnonymousTagLocations(true),
SuppressStrongLifetime(false), SuppressLifetimeQualifiers(false),
SuppressTypedefs(false), SuppressTemplateArgsInCXXConstructors(false),
SuppressDefaultTemplateArgs(true), Bool(LO.Bool),
Nullptr(LO.CPlusPlus11 || LO.C2x), NullptrTypeInNamespace(LO.CPlusPlus),
Restrict(LO.C99), Alignof(LO.CPlusPlus11),
UnderscoreAlignof(LO.C11), UseVoidForZeroParams(!LO.CPlusPlus),
SuppressDefaultTemplateArgs(true), SuppressFinalSpecifier(false),
Bool(LO.Bool), Nullptr(LO.CPlusPlus11 || LO.C2x),
NullptrTypeInNamespace(LO.CPlusPlus), Restrict(LO.C99),
Alignof(LO.CPlusPlus11), UnderscoreAlignof(LO.C11),
UseVoidForZeroParams(!LO.CPlusPlus),
SplitTemplateClosers(!LO.CPlusPlus11), TerseOutput(false),
PolishForDeclaration(false), Half(LO.Half),
MSWChar(LO.MicrosoftExt && !LO.WChar), IncludeNewlines(true),
Expand Down Expand Up @@ -214,6 +215,9 @@ struct PrintingPolicy {
/// argument for the parameter.
unsigned SuppressDefaultTemplateArgs : 1;

/// When true, suppress printing final specifier.
unsigned SuppressFinalSpecifier : 1;

/// Whether we can use 'bool' rather than '_Bool' (even if the language
/// doesn't actually have 'bool', because, e.g., it is defined as a macro).
unsigned Bool : 1;
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/AST/DeclPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1017,7 +1017,7 @@ void DeclPrinter::VisitCXXRecordDecl(CXXRecordDecl *D) {
}
}

if (D->hasDefinition()) {
if (D->hasDefinition() && !Policy.SuppressFinalSpecifier) {
if (D->hasAttr<FinalAttr>()) {
Out << " final";
}
Expand Down
1 change: 1 addition & 0 deletions clang/lib/Sema/SemaSYCL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4816,6 +4816,7 @@ class SYCLFwdDeclEmitter
Policy.SuppressUnwrittenScope = true;
Policy.PrintCanonicalTypes = true;
Policy.SkipCanonicalizationOfTemplateTypeParms = true;
Policy.SuppressFinalSpecifier = true;
}

void Visit(QualType T) {
Expand Down
9 changes: 9 additions & 0 deletions clang/test/CodeGenSYCL/integration_header.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
//
// CHECK: #include <sycl/detail/kernel_desc.hpp>
//
// CHECK: // Forward declarations of templated kernel function types:
// CHECK: class first_kernel;
// CHECK-NEXT: namespace second_namespace {
// CHECK-NEXT: template <typename T> class second_kernel;
Expand All @@ -11,6 +12,7 @@
// CHECK-NEXT: template <int DimX> struct namespaced_arg;
// CHECK-NEXT: }
// CHECK-NEXT: template <typename ...Ts> class fourth_kernel;
// CHECK: class FinalClass;
//
// CHECK: static constexpr
// CHECK-NEXT: const char* const kernel_names[] = {
Expand All @@ -19,6 +21,7 @@
// CHECK-NEXT: "_ZTS13fourth_kernelIJN15template_arg_ns14namespaced_argILi1EEEEE"
// CHECK-NEXT: "_ZTSZ4mainE16accessor_in_base"
// CHECK-NEXT: "_ZTSZ4mainE15annotated_types"
// CHECK-NEXT: "_ZTS10FinalClass"
// CHECK-NEXT: };
//
// CHECK: static constexpr
Expand Down Expand Up @@ -54,6 +57,8 @@
// CHECK-NEXT: { kernel_param_kind_t::kind_pointer, 8, 8 },
// CHECK-NEXT: { kernel_param_kind_t::kind_pointer, 8, 16 },
// CHECK-EMPTY:
// CHECK-NEXT: //--- _ZTS10FinalClass
// CHECK-EMPTY:
// CHECK-NEXT: { kernel_param_kind_t::kind_invalid, -987654321, -987654321 },
// CHECK-NEXT: };
//
Expand Down Expand Up @@ -110,6 +115,8 @@ struct captured : base, base2 {

struct MockProperty {};

class FinalClass final {};

int main() {

sycl::accessor<char, 1, sycl::access::mode::read> acc1;
Expand Down Expand Up @@ -160,5 +167,7 @@ int main() {
(void)AP3;
});

kernel_single_task<class FinalClass>([=]() { });

return 0;
}