Skip to content

Commit 9eeb782

Browse files
[SYCL] Fix forward declaration in integration header (#9087)
Do not emit 'final' keyword on forward declaration of classes in integration header.
1 parent 0568928 commit 9eeb782

File tree

4 files changed

+19
-5
lines changed

4 files changed

+19
-5
lines changed

clang/include/clang/AST/PrettyPrinter.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,11 @@ struct PrintingPolicy {
6464
ConstantArraySizeAsWritten(false), AnonymousTagLocations(true),
6565
SuppressStrongLifetime(false), SuppressLifetimeQualifiers(false),
6666
SuppressTypedefs(false), SuppressTemplateArgsInCXXConstructors(false),
67-
SuppressDefaultTemplateArgs(true), Bool(LO.Bool),
68-
Nullptr(LO.CPlusPlus11 || LO.C2x), NullptrTypeInNamespace(LO.CPlusPlus),
69-
Restrict(LO.C99), Alignof(LO.CPlusPlus11),
70-
UnderscoreAlignof(LO.C11), UseVoidForZeroParams(!LO.CPlusPlus),
67+
SuppressDefaultTemplateArgs(true), SuppressFinalSpecifier(false),
68+
Bool(LO.Bool), Nullptr(LO.CPlusPlus11 || LO.C2x),
69+
NullptrTypeInNamespace(LO.CPlusPlus), Restrict(LO.C99),
70+
Alignof(LO.CPlusPlus11), UnderscoreAlignof(LO.C11),
71+
UseVoidForZeroParams(!LO.CPlusPlus),
7172
SplitTemplateClosers(!LO.CPlusPlus11), TerseOutput(false),
7273
PolishForDeclaration(false), Half(LO.Half),
7374
MSWChar(LO.MicrosoftExt && !LO.WChar), IncludeNewlines(true),
@@ -214,6 +215,9 @@ struct PrintingPolicy {
214215
/// argument for the parameter.
215216
unsigned SuppressDefaultTemplateArgs : 1;
216217

218+
/// When true, suppress printing final specifier.
219+
unsigned SuppressFinalSpecifier : 1;
220+
217221
/// Whether we can use 'bool' rather than '_Bool' (even if the language
218222
/// doesn't actually have 'bool', because, e.g., it is defined as a macro).
219223
unsigned Bool : 1;

clang/lib/AST/DeclPrinter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1017,7 +1017,7 @@ void DeclPrinter::VisitCXXRecordDecl(CXXRecordDecl *D) {
10171017
}
10181018
}
10191019

1020-
if (D->hasDefinition()) {
1020+
if (D->hasDefinition() && !Policy.SuppressFinalSpecifier) {
10211021
if (D->hasAttr<FinalAttr>()) {
10221022
Out << " final";
10231023
}

clang/lib/Sema/SemaSYCL.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4889,6 +4889,7 @@ class SYCLFwdDeclEmitter
48894889
Policy.SuppressUnwrittenScope = true;
48904890
Policy.PrintCanonicalTypes = true;
48914891
Policy.SkipCanonicalizationOfTemplateTypeParms = true;
4892+
Policy.SuppressFinalSpecifier = true;
48924893
}
48934894

48944895
void Visit(QualType T) {

clang/test/CodeGenSYCL/integration_header.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
//
44
// CHECK: #include <sycl/detail/kernel_desc.hpp>
55
//
6+
// CHECK: // Forward declarations of templated kernel function types:
67
// CHECK: class first_kernel;
78
// CHECK-NEXT: namespace second_namespace {
89
// CHECK-NEXT: template <typename T> class second_kernel;
@@ -11,6 +12,7 @@
1112
// CHECK-NEXT: template <int DimX> struct namespaced_arg;
1213
// CHECK-NEXT: }
1314
// CHECK-NEXT: template <typename ...Ts> class fourth_kernel;
15+
// CHECK: class FinalClass;
1416
//
1517
// CHECK: static constexpr
1618
// CHECK-NEXT: const char* const kernel_names[] = {
@@ -19,6 +21,7 @@
1921
// CHECK-NEXT: "_ZTS13fourth_kernelIJN15template_arg_ns14namespaced_argILi1EEEEE"
2022
// CHECK-NEXT: "_ZTSZ4mainE16accessor_in_base"
2123
// CHECK-NEXT: "_ZTSZ4mainE15annotated_types"
24+
// CHECK-NEXT: "_ZTS10FinalClass"
2225
// CHECK-NEXT: };
2326
//
2427
// CHECK: static constexpr
@@ -54,6 +57,8 @@
5457
// CHECK-NEXT: { kernel_param_kind_t::kind_pointer, 8, 8 },
5558
// CHECK-NEXT: { kernel_param_kind_t::kind_pointer, 8, 16 },
5659
// CHECK-EMPTY:
60+
// CHECK-NEXT: //--- _ZTS10FinalClass
61+
// CHECK-EMPTY:
5762
// CHECK-NEXT: { kernel_param_kind_t::kind_invalid, -987654321, -987654321 },
5863
// CHECK-NEXT: };
5964
//
@@ -110,6 +115,8 @@ struct captured : base, base2 {
110115

111116
struct MockProperty {};
112117

118+
class FinalClass final {};
119+
113120
int main() {
114121

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

170+
kernel_single_task<class FinalClass>([=]() { });
171+
163172
return 0;
164173
}

0 commit comments

Comments
 (0)