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

Tom Honermann via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 13 20:52:08 PDT 2025


================
@@ -0,0 +1,78 @@
+// RUN: %clang_cc1 -fsycl-is-device -triple spir64-unknown-unknown -disable-llvm-passes -emit-llvm %s -o - | FileCheck %s
+
+// This test code generation when sycl_external attribute is used
+
+// Function defined and not used - symbols emitted
+[[clang::sycl_external]] int square(int x) { return x*x; }
+// CHECK: define dso_local spir_func noundef i32 @_Z6squarei
+
+// Function defined and used - symbols emitted
+[[clang::sycl_external]] int squareUsed(int x) { return x*x; }
+// CHECK: define dso_local spir_func noundef i32 @_Z10squareUsedi
+
+// Constexpr function defined and not used - symbols emitted
+[[clang::sycl_external]] constexpr int squareInlined(int x) { return x*x; }
+// CHECK: define linkonce_odr spir_func noundef i32 @_Z13squareInlinedi
+
+// Function declared but not defined or used - no symbols emitted
+[[clang::sycl_external]] int declOnly();
+// CHECK-NOT: define {{.*}} i32 @_Z8declOnlyv
----------------
tahonermann wrote:

Let's also validate no declaration is emitted.
```suggestion
// CHECK-NOT: define {{.*}} i32 @_Z8declOnlyv
// CHECK-NOT: declare {{.*}}i32 @_Z8declOnlyv
```

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


More information about the cfe-commits mailing list