https://github.com/bader created 
https://github.com/llvm/llvm-project/pull/200096

- --version now returns EXIT_SUCCESS immediately after printing; previously it 
fell through into the rest of main.
- Report an error early when no input files are provided rather than hitting 
the assert inside linkDeviceCode.

>From 1e79dde1493ea29e293d576e9861c501ef77a775 Mon Sep 17 00:00:00 2001
From: Alexey Bader <[email protected]>
Date: Wed, 27 May 2026 10:26:39 -0700
Subject: [PATCH] [clang-sycl-linker] Fix --version exit code and empty-input
 error

- --version now returns EXIT_SUCCESS immediately after printing; previously
  it fell through into the rest of main.
- Report an error early when no input files are provided rather than
  hitting the assert inside linkDeviceCode.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
---
 .../OffloadTools/clang-sycl-linker/options.ll | 40 +++++++++++++++++++
 .../clang-sycl-linker/ClangSYCLLinker.cpp     |  7 +++-
 2 files changed, 46 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/OffloadTools/clang-sycl-linker/options.ll

diff --git a/clang/test/OffloadTools/clang-sycl-linker/options.ll 
b/clang/test/OffloadTools/clang-sycl-linker/options.ll
new file mode 100644
index 0000000000000..55b691187028f
--- /dev/null
+++ b/clang/test/OffloadTools/clang-sycl-linker/options.ll
@@ -0,0 +1,40 @@
+; Tests non-functional command line options of the clang-sycl-linker tool.
+;
+; REQUIRES: spirv-registered-target
+;
+; Test --help
+; RUN: clang-sycl-linker --help | FileCheck %s --check-prefix=HELP
+; HELP: OVERVIEW: A utility that wraps around several steps required to link 
SYCL device files.
+; HELP: USAGE: clang-sycl-linker
+; HELP: OPTIONS:
+;
+; Test --version
+; RUN: clang-sycl-linker --version | FileCheck %s --check-prefix=VERSION
+; VERSION: clang-sycl-linker version
+;
+; Test missing input files
+; RUN: not clang-sycl-linker --dry-run -triple=spirv64 -o %t.out 2>&1 | 
FileCheck %s --check-prefix=NO-INPUT
+; NO-INPUT: No input files provided
+;
+; Create a simple bitcode file for subsequent tests
+; RUN: llvm-as %s -o %t.bc
+;
+; Test --print-linked-module
+; RUN: clang-sycl-linker --dry-run -triple=spirv64 %t.bc --print-linked-module 
-o %t.out > %t.ll
+; RUN: FileCheck %s --check-prefix=PRINT-LINKED < %t.ll
+; PRINT-LINKED: target triple = "spirv64"
+;
+; Test --save-temps
+; RUN: rm -rf %t.dir && mkdir -p %t.dir
+; RUN: cd %t.dir && clang-sycl-linker --dry-run -triple=spirv64 %t.bc 
--save-temps -o out.spv
+; RUN: ls %t.dir/out.spv-*.bc | count 1
+;
+; Test --spirv-dump-device-code (should parse without error)
+; RUN: clang-sycl-linker --dry-run -triple=spirv64 %t.bc 
--spirv-dump-device-code=%t.dir -o %t.out
+;
+; Test --spirv-dump-device-code with no value (fallback to ./)
+; RUN: clang-sycl-linker --dry-run -triple=spirv64 %t.bc 
--spirv-dump-device-code= -o %t.out
+
+target datalayout = 
"e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-n8:16:32:64-G1"
+target triple = "spirv64"
+
diff --git a/clang/tools/clang-sycl-linker/ClangSYCLLinker.cpp 
b/clang/tools/clang-sycl-linker/ClangSYCLLinker.cpp
index 88a09d0a3ecc7..0d83c93065e3f 100644
--- a/clang/tools/clang-sycl-linker/ClangSYCLLinker.cpp
+++ b/clang/tools/clang-sycl-linker/ClangSYCLLinker.cpp
@@ -786,8 +786,10 @@ int main(int argc, char **argv) {
     return EXIT_SUCCESS;
   }
 
-  if (Args.hasArg(OPT_version))
+  if (Args.hasArg(OPT_version)) {
     printVersion(outs());
+    return EXIT_SUCCESS;
+  }
 
   Verbose = Args.hasArg(OPT_verbose);
   DryRun = Args.hasArg(OPT_dry_run);
@@ -812,6 +814,9 @@ int main(int argc, char **argv) {
   if (!FilesOrErr)
     reportError(FilesOrErr.takeError());
 
+  if (FilesOrErr->empty())
+    reportError(createStringError("No input files provided"));
+
   // Run SYCL linking process on the generated inputs.
   if (Error Err = runSYCLLink(*FilesOrErr, Args))
     reportError(std::move(Err));

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to