[clang] [Clang] diagnosing missing Vulkan environment when using SPIR-V triple (PR #190840)
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Thu Apr 16 06:18:23 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:
This should also be a diagnostic instead of an assertion, similar to what you did for Vulkan, because it has the same bug: https://godbolt.org/z/TsrfhfWT8
You should also add a RUN line to the test case for that; you can use `--check-prefix` on the `FileCheck` line to distinguish between the two RUN lines for checking the diagnostic output, like done here: https://github.com/llvm/llvm-project/blob/46bbbde1f3c3bf3a00ae19c3157f7425899b1e87/clang/test/Frontend/gnu-inline.c#L1
https://github.com/llvm/llvm-project/pull/190840
More information about the cfe-commits
mailing list