Skip to content

Llvm diagnostic spirv#189964#190840

Open
PrabbyDD wants to merge 3 commits intollvm:mainfrom
PrabbyDD:llvmDiagnosticSPIRV#189964
Open

Llvm diagnostic spirv#189964#190840
PrabbyDD wants to merge 3 commits intollvm:mainfrom
PrabbyDD:llvmDiagnosticSPIRV#189964

Conversation

@PrabbyDD
Copy link
Copy Markdown

@PrabbyDD PrabbyDD commented Apr 7, 2026

Fixes issue #189964

When a user passes '-target spirv' without specififying a vulkan environment ttriple, SPIRVTargetInfo will fire an assert instead of throwing an error diagnostic. Added this diagnostic in CompilerInstance::createTarget() before target is initialized. Fixes #189964

PrabbyDD added 2 commits April 6, 2026 15:43
…V target for release

When a user passes '-target spirv' without specififying a vulkan environment ttriple, SPIRVTargetInfo will fire an assert instead of throwing an error diagnostic. Added this diagnostic in CompilerInstance::createTarget() before target is initialized. Fixes llvm#189964
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 7, 2026

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@llvmbot llvmbot added clang Clang issues not falling into any other category clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Apr 7, 2026
@llvmbot
Copy link
Copy Markdown
Member

llvmbot commented Apr 7, 2026

@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clang-driver

Author: PrabbyDD

Changes

Fixes issue #189964


Full diff: https://github.com/llvm/llvm-project/pull/190840.diff

3 Files Affected:

  • (modified) clang/include/clang/Basic/DiagnosticFrontendKinds.td (+3)
  • (modified) clang/lib/Frontend/CompilerInstance.cpp (+11)
  • (added) clang/test/Driver/spirv-target-validation.c (+4)
diff --git a/clang/include/clang/Basic/DiagnosticFrontendKinds.td b/clang/include/clang/Basic/DiagnosticFrontendKinds.td
index 62b74574102e4..0a3e4e82a79e5 100644
--- a/clang/include/clang/Basic/DiagnosticFrontendKinds.td
+++ b/clang/include/clang/Basic/DiagnosticFrontendKinds.td
@@ -43,6 +43,9 @@ def note_fe_backend_resource_limit: Note<"%0 (%1) exceeds limit (%2) in '%3'">,
 def remark_fe_backend_plugin: Remark<"%0">, BackendInfo, InGroup<RemarkBackendPlugin>;
 def note_fe_backend_plugin: Note<"%0">, BackendInfo;
 
+def err_spirv_requires_vulkan : Error<
+    "SPIR-V target requires a Vulkan environment (e.g. '-target spirv64-unknown-vulkan1.3')">;
+
 def warn_fe_override_module : Warning<
     "overriding the module target triple with %0">,
     InGroup<DiagGroup<"override-module">>;
diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp
index 0b00ad7128c00..89898d3adfbae 100644
--- a/clang/lib/Frontend/CompilerInstance.cpp
+++ b/clang/lib/Frontend/CompilerInstance.cpp
@@ -112,6 +112,17 @@ void CompilerInstance::setTarget(TargetInfo *Value) { Target = Value; }
 void CompilerInstance::setAuxTarget(TargetInfo *Value) { AuxTarget = Value; }
 
 bool CompilerInstance::createTarget() {
+
+  // Validate Vulkan environment for SPIRV. 
+  llvm::Triple Triple(getInvocation().getTargetOpts().Triple);
+  if (Triple.getArch() == llvm::Triple::spirv) {
+    if (Triple.getOS() != llvm::Triple::Vulkan ||
+        Triple.getVulkanVersion() == llvm::VersionTuple(0)) {
+      getDiagnostics().Report(diag::err_spirv_requires_vulkan) << Triple.str();
+      return false;
+    }
+  }
+
   // Create the target instance.
   setTarget(TargetInfo::CreateTargetInfo(getDiagnostics(),
                                          getInvocation().getTargetOpts()));
diff --git a/clang/test/Driver/spirv-target-validation.c b/clang/test/Driver/spirv-target-validation.c
new file mode 100644
index 0000000000000..cde5b46c54b94
--- /dev/null
+++ b/clang/test/Driver/spirv-target-validation.c
@@ -0,0 +1,4 @@
+// RUN: %clang -target spirv %s 2>&1 | FileCheck %s
+// CHECK: error: SPIR-V target requires a Vulkan environment
+
+int main() { return 0; }
\ No newline at end of file

@PrabbyDD
Copy link
Copy Markdown
Author

PrabbyDD commented Apr 7, 2026

Hello! This is my first PR to LLVM. A small diagnostics fix. If there is any advice for newbie mistakes I might have made, I will gladly fix them. I am trying to work my way up from smaller issues to larger ones in clang because it is complex. I tried to include short but meaningful comments in the code, a unit test that mimics others I saw, and meaningful commit messages. Thanks.

@Sirraide Sirraide requested a review from AaronBallman April 7, 2026 23:16
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 7, 2026

⚠️ C/C++ code formatter, clang-format found issues in your code. ⚠️

You can test this locally with the following command:
git-clang-format --diff origin/main HEAD --extensions c,cpp -- clang/test/Driver/spirv-target-validation.c clang/lib/Frontend/CompilerInstance.cpp --diff_from_common_commit

⚠️
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing origin/main to the base branch/commit you want to compare against.
⚠️

View the diff from clang-format here.
diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp
index 89898d3ad..b51f9027b 100644
--- a/clang/lib/Frontend/CompilerInstance.cpp
+++ b/clang/lib/Frontend/CompilerInstance.cpp
@@ -113,7 +113,7 @@ void CompilerInstance::setAuxTarget(TargetInfo *Value) { AuxTarget = Value; }
 
 bool CompilerInstance::createTarget() {
 
-  // Validate Vulkan environment for SPIRV. 
+  // Validate Vulkan environment for SPIRV.
   llvm::Triple Triple(getInvocation().getTargetOpts().Triple);
   if (Triple.getArch() == llvm::Triple::spirv) {
     if (Triple.getOS() != llvm::Triple::Vulkan ||

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 7, 2026

🐧 Linux x64 Test Results

  • 87264 tests passed
  • 1387 tests skipped
  • 2 tests failed

Failed Tests

(click on a test name to see its output)

Clang

Clang.Driver/spirv-target-validation.c
Exit Code: 1

Command Output (stdout):
--
# RUN: at line 1
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/clang -target spirv /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/Driver/spirv-target-validation.c 2>&1 | /home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/FileCheck /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/Driver/spirv-target-validation.c
# executed command: /home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/clang -target spirv /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/Driver/spirv-target-validation.c
# note: command had no output on stdout or stderr
# error: command failed with exit status: 1
# executed command: /home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/FileCheck /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/Driver/spirv-target-validation.c
# note: command had no output on stdout or stderr

--

lldb-api

lldb-api.commands/process/attach/TestProcessAttach.py
Script:
--
/usr/bin/python3 /home/gha/actions-runner/_work/llvm-project/llvm-project/lldb/test/API/dotest.py -u CXXFLAGS -u CFLAGS --env LLVM_LIBS_DIR=/home/gha/actions-runner/_work/llvm-project/llvm-project/build/./lib --env LLVM_INCLUDE_DIR=/home/gha/actions-runner/_work/llvm-project/llvm-project/build/include --env LLVM_TOOLS_DIR=/home/gha/actions-runner/_work/llvm-project/llvm-project/build/./bin --libcxx-include-dir /home/gha/actions-runner/_work/llvm-project/llvm-project/build/include/c++/v1 --libcxx-include-target-dir /home/gha/actions-runner/_work/llvm-project/llvm-project/build/include/x86_64-unknown-linux-gnu/c++/v1 --libcxx-library-dir /home/gha/actions-runner/_work/llvm-project/llvm-project/build/./lib/x86_64-unknown-linux-gnu --arch x86_64 --build-dir /home/gha/actions-runner/_work/llvm-project/llvm-project/build/lldb-test-build.noindex --lldb-module-cache-dir /home/gha/actions-runner/_work/llvm-project/llvm-project/build/lldb-test-build.noindex/module-cache-lldb/lldb-api --clang-module-cache-dir /home/gha/actions-runner/_work/llvm-project/llvm-project/build/lldb-test-build.noindex/module-cache-clang/lldb-api --executable /home/gha/actions-runner/_work/llvm-project/llvm-project/build/./bin/lldb --compiler /home/gha/actions-runner/_work/llvm-project/llvm-project/build/./bin/clang --dsymutil /home/gha/actions-runner/_work/llvm-project/llvm-project/build/./bin/dsymutil --make /usr/bin/gmake --llvm-tools-dir /home/gha/actions-runner/_work/llvm-project/llvm-project/build/./bin --lldb-obj-root /home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/lldb --lldb-libs-dir /home/gha/actions-runner/_work/llvm-project/llvm-project/build/./lib --cmake-build-type Release /home/gha/actions-runner/_work/llvm-project/llvm-project/lldb/test/API/commands/process/attach -p TestProcessAttach.py
--
Exit Code: 1

Command Output (stdout):
--
lldb version 23.0.0git (https://github.com/llvm/llvm-project revision 6323f5a020b5435661e73cc001e8d44ce336a57d)
  clang revision 6323f5a020b5435661e73cc001e8d44ce336a57d
  llvm revision 6323f5a020b5435661e73cc001e8d44ce336a57d
Skipping the following test categories: msvcstl, dsym, pdb, gmodules, debugserver, objc

--
Command Output (stderr):
--
PASS: LLDB (/home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/clang-x86_64) :: test_attach_to_process_by_id (TestProcessAttach.ProcessAttachTestCase.test_attach_to_process_by_id)
PASS: LLDB (/home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/clang-x86_64) :: test_attach_to_process_by_id_autocontinue (TestProcessAttach.ProcessAttachTestCase.test_attach_to_process_by_id_autocontinue)
FAIL: LLDB (/home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/clang-x86_64) :: test_attach_to_process_by_id_correct_executable_offset (TestProcessAttach.ProcessAttachTestCase.test_attach_to_process_by_id_correct_executable_offset)
Log Files:
 - /home/gha/actions-runner/_work/llvm-project/llvm-project/build/lldb-test-build.noindex/commands/process/attach/TestProcessAttach.test_attach_to_process_by_id_correct_executable_offset/Failure_test_attach_to_process_by_id_correct_executable_offset.log
PASS: LLDB (/home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/clang-x86_64) :: test_attach_to_process_by_name (TestProcessAttach.ProcessAttachTestCase.test_attach_to_process_by_name)
PASS: LLDB (/home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/clang-x86_64) :: test_attach_to_process_from_different_dir_by_id (TestProcessAttach.ProcessAttachTestCase.test_attach_to_process_from_different_dir_by_id)
======================================================================
FAIL: test_attach_to_process_by_id_correct_executable_offset (TestProcessAttach.ProcessAttachTestCase.test_attach_to_process_by_id_correct_executable_offset)
   Test that after attaching to a process the executable offset
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/gha/actions-runner/_work/llvm-project/llvm-project/lldb/test/API/commands/process/attach/TestProcessAttach.py", line 113, in test_attach_to_process_by_id_correct_executable_offset
    self.runCmd("process attach -p " + str(popen.pid))
  File "/home/gha/actions-runner/_work/llvm-project/llvm-project/lldb/packages/Python/lldbsuite/test/lldbtest.py", line 1053, in runCmd
    self.assertTrue(self.res.Succeeded(), msg + output)
AssertionError: False is not true : Command 'process attach -p 725236' did not return successfully
Error output:
error: attach failed: The current value of ptrace_scope is 1, which can cause ptrace to fail to attach to a running process. To fix this, run:
	sudo sysctl -w kernel.yama.ptrace_scope=0
For more information, see: https://www.kernel.org/doc/Documentation/security/Yama.txt.

Config=x86_64-/home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/clang
----------------------------------------------------------------------
Ran 5 tests in 68.496s

FAILED (failures=1)

--

If these failures are unrelated to your changes (for example tests are broken or flaky at HEAD), please open an issue at https://github.com/llvm/llvm-project/issues and add the infrastructure label.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 7, 2026

🪟 Windows x64 Test Results

  • 53513 tests passed
  • 1076 tests skipped
  • 1 test failed

Failed Tests

(click on a test name to see its output)

Clang

Clang.Driver/spirv-target-validation.c
Exit Code: 1

Command Output (stdout):
--
# RUN: at line 1
c:\_work\llvm-project\llvm-project\build\bin\clang.exe -target spirv C:\_work\llvm-project\llvm-project\clang\test\Driver\spirv-target-validation.c 2>&1 | c:\_work\llvm-project\llvm-project\build\bin\filecheck.exe C:\_work\llvm-project\llvm-project\clang\test\Driver\spirv-target-validation.c
# executed command: 'c:\_work\llvm-project\llvm-project\build\bin\clang.exe' -target spirv 'C:\_work\llvm-project\llvm-project\clang\test\Driver\spirv-target-validation.c'
# note: command had no output on stdout or stderr
# error: command failed with exit status: 1
# executed command: 'c:\_work\llvm-project\llvm-project\build\bin\filecheck.exe' 'C:\_work\llvm-project\llvm-project\clang\test\Driver\spirv-target-validation.c'
# note: command had no output on stdout or stderr

--

If these failures are unrelated to your changes (for example tests are broken or flaky at HEAD), please open an issue at https://github.com/llvm/llvm-project/issues and add the infrastructure label.

@to268
Copy link
Copy Markdown
Contributor

to268 commented Apr 8, 2026

You should not format code (manually or automatically) outside of your changes. It makes it harder to review your PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[clang] Assertion failure if "-target spirv" is used

3 participants