From 9f53a78e4b67b2514e911ec62d183530882c251c Mon Sep 17 00:00:00 2001 From: premanandrao Date: Fri, 20 Sep 2024 13:34:15 -0400 Subject: [PATCH] [SYCL] Fix diagnostic about non-external function/variable (#15372) We were issuing a diagnostic when applying attributes like [[sycl_device]] or [[intel::device_indirectly_callable]] on functions/variables without external linkage - but the diagnostic text assumed that this occurred only with static entities or entities within unnamed namespaces. The following example demonstrates a case where the previous diagnostic text was misleading: ``` namespace { struct S {}; } [[sycl_device]] void foo(S); ``` --- clang/include/clang/Basic/DiagnosticSemaKinds.td | 5 ++--- clang/test/SemaSYCL/device-indirectly-callable-attr.cpp | 9 +++++++-- clang/test/SemaSYCL/device_global_external.cpp | 9 +++++++-- clang/test/SemaSYCL/sycl-device.cpp | 9 +++++++-- 4 files changed, 23 insertions(+), 9 deletions(-) diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 1e94b129fc387..f9ad5e54f2939 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -12486,9 +12486,8 @@ def err_sycl_function_attribute_mismatch : Error< def err_sycl_x_y_z_arguments_must_be_one : Error< "all %0 attribute arguments must be '1' when the %1 attribute argument is '0'">; def err_sycl_attribute_internal_decl - : Error<"%0 attribute cannot be applied to a " - "static %select{function|variable}1 or %select{function|variable}1 " - "in an anonymous namespace">; + : Error<"%0 attribute cannot be applied to a %select{function|variable}1" + " without external linkage">; def err_sycl_attribute_not_device_global : Error<"%0 attribute can only be applied to 'device_global' variables">; def err_fpga_attribute_incorrect_variable diff --git a/clang/test/SemaSYCL/device-indirectly-callable-attr.cpp b/clang/test/SemaSYCL/device-indirectly-callable-attr.cpp index a79f3f8eae244..80cf6fc602b5c 100644 --- a/clang/test/SemaSYCL/device-indirectly-callable-attr.cpp +++ b/clang/test/SemaSYCL/device-indirectly-callable-attr.cpp @@ -12,16 +12,21 @@ int N; void bar() {} -[[intel::device_indirectly_callable]] // expected-error {{'device_indirectly_callable' attribute cannot be applied to a static function or function in an anonymous namespace}} +[[intel::device_indirectly_callable]] // expected-error {{'device_indirectly_callable' attribute cannot be applied to a function without external linkage}} static void func1() {} namespace { -[[intel::device_indirectly_callable]] // expected-error {{'device_indirectly_callable' attribute cannot be applied to a static function or function in an anonymous namespace}} +[[intel::device_indirectly_callable]] // expected-error {{'device_indirectly_callable' attribute cannot be applied to a function without external linkage}} void func2() {} + +struct UnnX {}; } +[[intel::device_indirectly_callable]] // expected-error {{'device_indirectly_callable' attribute cannot be applied to a function without external linkage}} +void func4(UnnX) {} + class A { [[intel::device_indirectly_callable]] A() {} diff --git a/clang/test/SemaSYCL/device_global_external.cpp b/clang/test/SemaSYCL/device_global_external.cpp index a4824d2453e0e..5b95102096489 100644 --- a/clang/test/SemaSYCL/device_global_external.cpp +++ b/clang/test/SemaSYCL/device_global_external.cpp @@ -5,7 +5,7 @@ using namespace sycl::ext::oneapi; SYCL_EXTERNAL device_global glob; -// expected-error@+1{{'sycl_device' attribute cannot be applied to a static variable or variable in an anonymous namespace}} +// expected-error@+1{{'sycl_device' attribute cannot be applied to a variable without external linkage}} SYCL_EXTERNAL static device_global static_glob; namespace foo { @@ -20,10 +20,15 @@ struct RandomStruct { SYCL_EXTERNAL RandomStruct S; namespace { -// expected-error@+1{{'sycl_device' attribute cannot be applied to a static variable or variable in an anonymous namespace}} +// expected-error@+1{{'sycl_device' attribute cannot be applied to a variable without external linkage}} SYCL_EXTERNAL device_global same_name; + +struct UnnX {}; } // namespace +// expected-error@+1{{'sycl_device' attribute cannot be applied to a variable without external linkage}} +SYCL_EXTERNAL device_global dg_x; + // expected-error@+1{{'sycl_device' attribute can only be applied to 'device_global' variables}} SYCL_EXTERNAL int AAA; diff --git a/clang/test/SemaSYCL/sycl-device.cpp b/clang/test/SemaSYCL/sycl-device.cpp index 4d4004338166d..2e7e1d0f7f51d 100644 --- a/clang/test/SemaSYCL/sycl-device.cpp +++ b/clang/test/SemaSYCL/sycl-device.cpp @@ -12,14 +12,19 @@ int N; __attribute__((sycl_device(3))) // expected-error {{'sycl_device' attribute takes no arguments}} void bar() {} -__attribute__((sycl_device)) // expected-error {{'sycl_device' attribute cannot be applied to a static function or function in an anonymous namespace}} +__attribute__((sycl_device)) // expected-error {{'sycl_device' attribute cannot be applied to a function without external linkage}} static void func1() {} namespace { - __attribute__((sycl_device)) // expected-error {{'sycl_device' attribute cannot be applied to a static function or function in an anonymous namespace}} + __attribute__((sycl_device)) // expected-error {{'sycl_device' attribute cannot be applied to a function without external linkage}} void func2() {} + + struct UnnX {}; } +__attribute__((sycl_device)) // expected-error {{'sycl_device' attribute cannot be applied to a function without external linkage}} + void func4(UnnX) {} + class A { __attribute__((sycl_device)) A() {}