Skip to content

Commit 4db4101

Browse files
committed
Use existing diagnostic and address other minor comments
1 parent 45f7b09 commit 4db4101

File tree

5 files changed

+13
-13
lines changed

5 files changed

+13
-13
lines changed

clang/include/clang/Basic/Attr.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1644,7 +1644,7 @@ def DeviceKernel : DeclOrTypeAttr {
16441644
def SYCLExternal : InheritableAttr {
16451645
let Spellings = [Clang<"sycl_external">];
16461646
let Subjects = SubjectList<[Function], ErrorDiag>;
1647-
let LangOpts = [SYCLDevice];
1647+
let LangOpts = [SYCLHost, SYCLDevice];
16481648
let Documentation = [SYCLExternalDocs];
16491649
}
16501650

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12884,10 +12884,9 @@ def err_sycl_attribute_invalid_linkage : Error<
1288412884
"'sycl_external' can only be applied to functions with external linkage">;
1288512885
def err_sycl_attribute_avoid_main : Error<
1288612886
"'sycl_external' cannot be applied to the 'main' function">;
12887-
def err_sycl_attribute_avoid_deleted_function : Error<
12888-
"'sycl_external' cannot be applied to an explicitly deleted function">;
12889-
def err_sycl_attribute_missing_on_first_decl
12890-
: Error<"'sycl_external' must be applied to the first declaration">;
12887+
def err_sycl_attribute_avoid_deleted_function
12888+
: Error<"'sycl_external' cannot be applied to an explicitly deleted "
12889+
"function">;
1289112890

1289212891
// SYCL kernel entry point diagnostics
1289312892
def err_sycl_entry_point_invalid : Error<

clang/lib/Sema/SemaDecl.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4084,16 +4084,18 @@ bool Sema::MergeFunctionDecl(FunctionDecl *New, NamedDecl *&OldD, Scope *S,
40844084
diag::note_carries_dependency_missing_first_decl) << 0/*Function*/;
40854085
}
40864086

4087-
// SYCL spec 2020
4088-
// The first declaration of a function with external linkage must
4089-
// specify sycl_external attribute.
4090-
// Subsequent declarations may optionally specify this attribute.
4087+
// SYCL 2020 section 5.10.1, "SYCL functions and member functions linkage":
4088+
// When a function is declared with sycl_external, that attribute must be
4089+
// used on the first declaration of that function in the translation unit.
4090+
// Redeclarations of the function in the same translation unit may
4091+
// optionally use sycl_external, but this is not required.
40914092
if (LangOpts.SYCLIsDevice) {
40924093
const SYCLExternalAttr *SEA = New->getAttr<SYCLExternalAttr>();
40934094
if (SEA && !Old->hasAttr<SYCLExternalAttr>()) {
4094-
Diag(SEA->getLocation(), diag::err_sycl_attribute_missing_on_first_decl)
4095+
Diag(SEA->getLocation(), diag::err_attribute_missing_on_first_decl)
40954096
<< SEA;
40964097
Diag(Old->getLocation(), diag::note_previous_declaration);
4098+
New->dropAttr<SYCLExternalAttr>();
40974099
}
40984100
}
40994101

clang/test/CodeGenSYCL/kernel-caller-entry-point.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,7 @@ int main() {
100100

101101
// Verify that SYCL kernel caller functions are emitted for each device target.
102102
//
103-
// main() shouldn't be emitted in device code. It is not annotated with
104-
// sycl_kernel_entry_point or sycl_external attributes.
103+
// main() shouldn't be emitted in device code.
105104
// CHECK-NOT: define {{[a-z_ ]*}}noundef i32 @main() #0
106105

107106
// IR for the SYCL kernel caller function generated for

clang/test/SemaSYCL/sycl-external-attr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ namespace {
1818
// The first declaration of a SYCL external function is required to have this attribute.
1919
int foo(); // expected-note {{previous declaration is here}}
2020

21-
[[clang::sycl_external]] int foo(); // expected-error {{'sycl_external' must be applied to the first declaration}}
21+
[[clang::sycl_external]] int foo(); // expected-error {{'clang::sycl_external' attribute does not appear on the first declaration}}
2222

2323
// Subsequent declrations of a SYCL external function may optionally specify this attribute.
2424
[[clang::sycl_external]] int boo();

0 commit comments

Comments
 (0)