From fadd62719918f6313e599c9d9d646591e59f6cde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nathan=20Gau=C3=ABr?= Date: Tue, 30 Jan 2024 15:27:59 +0100 Subject: [PATCH] [SPIR-V] Fix invalid optional read (#6221) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When the env isn't valid, we emit an error. But instead of returning, we continued and still tried to load the optional value, which triggered an assert. Signed-off-by: Nathan Gauër --- tools/clang/lib/SPIRV/FeatureManager.cpp | 1 + .../clang/test/CodeGenSPIRV/spirv.environment.invalid.hlsl | 6 ++++++ 2 files changed, 7 insertions(+) create mode 100644 tools/clang/test/CodeGenSPIRV/spirv.environment.invalid.hlsl diff --git a/tools/clang/lib/SPIRV/FeatureManager.cpp b/tools/clang/lib/SPIRV/FeatureManager.cpp index 2a355a96eb..b4888d41fe 100644 --- a/tools/clang/lib/SPIRV/FeatureManager.cpp +++ b/tools/clang/lib/SPIRV/FeatureManager.cpp @@ -85,6 +85,7 @@ FeatureManager::FeatureManager(DiagnosticsEngine &de, emitNote("allowed options are:\n vulkan1.0\n vulkan1.1\n " "vulkan1.1spirv1.4\n vulkan1.2\n vulkan1.3\n universal1.5", {}); + return; } targetEnv = *targetEnvOpt; diff --git a/tools/clang/test/CodeGenSPIRV/spirv.environment.invalid.hlsl b/tools/clang/test/CodeGenSPIRV/spirv.environment.invalid.hlsl new file mode 100644 index 0000000000..a130f4a1f3 --- /dev/null +++ b/tools/clang/test/CodeGenSPIRV/spirv.environment.invalid.hlsl @@ -0,0 +1,6 @@ +// RUN: not %dxc -T cs_6_0 -E main -fspv-target-env=vulkan1.1spirv1.3 %s -spirv 2>&1 | FileCheck %s + +[numthreads(1, 1, 1)] +void main() { } + +// CHECK: error: unknown SPIR-V target environment 'vulkan1.1spirv1.3'