[clang] [Clang] diagnosing missing Vulkan environment when using SPIR-V triple (PR #190840)

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Fri Apr 17 03:57:08 PDT 2026


================
@@ -341,20 +343,27 @@ class LLVM_LIBRARY_VISIBILITY SPIRVTargetInfo : public BaseSPIRVTargetInfo {
       : BaseSPIRVTargetInfo(Triple, Opts) {
     assert(Triple.getArch() == llvm::Triple::spirv &&
            "Invalid architecture for Logical SPIR-V.");
-    assert(Triple.getOS() == llvm::Triple::Vulkan &&
-           Triple.getVulkanVersion() != llvm::VersionTuple(0) &&
-           "Logical SPIR-V requires a valid Vulkan environment.");
-    assert(Triple.getEnvironment() >= llvm::Triple::Pixel &&
-           Triple.getEnvironment() <= llvm::Triple::Amplification &&
-           "Logical SPIR-V environment must be a valid shader stage.");
     PointerWidth = PointerAlign = 64;
 
     // SPIR-V IDs are represented with a single 32-bit word.
     SizeType = TargetInfo::UnsignedInt;
-    VectorsAreElementAligned = true;
     resetDataLayout();
   }
 
+  // SPIR-V targeting requires a fully specified Vulkan environment.
+  // Validate here before CreateTargetInfo() to emit a proper diagnostic
+  bool validateTarget(DiagnosticsEngine &Diags) const override {
+    if (getTriple().getOS() != llvm::Triple::Vulkan ||
+        getTriple().getVulkanVersion() == llvm::VersionTuple(0)) {
+      Diags.Report(diag::err_fe_spirv_requires_vulkan);
+      return false;
+    }
+    assert(getTriple().getEnvironment() >= llvm::Triple::Pixel &&
----------------
AaronBallman wrote:

> I added the test but just realized its failing...so I gotta fix that first before anything else. The checks are run one after another correct? And the check prefix's separate them from one another?

Yes, each RUN line is run sequentially and the check prefix is the way to distinguish between the RUN lines for your testing expectations.

> I changed the test case to reflect the command that you used in the godbolt link posted above, but the test is still failing. I tried looking at the verbose output to see what was going on and it just seems to be bypassing the shader stage check, but the vulkan env test is still working. Not too sure what to do from here, but ill still poke around a bit more.

In case you don't find the root cause, I just enabled the workflows to run testing on our CI so we can all see the failures and try to help out.

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


More information about the cfe-commits mailing list