[clang] [clang][SYCL] Add sycl_external attribute and restrict emitting device code (PR #140282)

via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 14 07:47:29 PDT 2025


================
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -fsycl-is-device -fsyntax-only -verify %s
+
+// expected-error at +1{{'clang::sycl_external' attribute only applies to functions}}
+[[clang::sycl_external]] int a;
+
+
+// expected-error at +2{{'clang::sycl_external' attribute only applies to functions}}
+struct s {
+[[clang::sycl_external]] int b;
+};
+
+// expected-error at +1{{'clang::sycl_external' attribute takes no arguments}}
+[[clang::sycl_external(3)]] void bar() {}
+
+// FIXME: The first declaration of a function is required to have the attribute.
+// The attribute may be optionally present on subsequent declarations
+int foo(int c);
+
+[[clang::sycl_external]] void foo();
----------------
schittir wrote:

 bad2() and bad4() in the examples you shared in the comment above generate an "expected expression" error, which is not specific to this attribute. Would you deem them necessary? 

https://github.com/llvm/llvm-project/pull/140282


More information about the cfe-commits mailing list