diff --git a/tests/ui/dis/panic_builtin_bounds_check.rs b/tests/ui/dis/panic_builtin_bounds_check.rs new file mode 100644 index 0000000000..9430008694 --- /dev/null +++ b/tests/ui/dis/panic_builtin_bounds_check.rs @@ -0,0 +1,31 @@ +#![crate_name = "panic_builtin_bounds_check"] + +// Test that bounds checking panics get converted to `debugPrintf` correctly. + +// build-pass +// compile-flags: -C target-feature=+ext:SPV_KHR_non_semantic_info +// compile-flags: -C llvm-args=--abort-strategy=debug-printf +// compile-flags: -C llvm-args=--disassemble + +// FIXME(eddyb) consider using such replacements also for dealing +// with `OpLine` changing all the time (esp. in libcore functions). +// +// normalize-stderr-test "; (SPIR-V|Generator: rspirv|Version: 1\.\d+|Bound: \d+)\n" -> "" +// normalize-stderr-test "OpCapability VulkanMemoryModel\n" -> "" +// normalize-stderr-test "OpSource .*\n" -> "" +// normalize-stderr-test "OpExtension .SPV_KHR_vulkan_memory_model.\n" -> "" +// normalize-stderr-test "OpMemoryModel Logical Vulkan" -> "OpMemoryModel Logical Simple" + +// FIXME(eddyb) handle this one in the test runner. +// normalize-stderr-test "\S*/lib/rustlib/" -> "$$SYSROOT/lib/rustlib/" + +use spirv_std::spirv; + +fn array_bounds_check(x: [u32; 4], i: usize) -> u32 { + x[i] +} + +#[spirv(fragment)] +pub fn main() { + array_bounds_check([0, 1, 2, 3], 5); +} diff --git a/tests/ui/dis/panic_builtin_bounds_check.stderr b/tests/ui/dis/panic_builtin_bounds_check.stderr new file mode 100644 index 0000000000..68ea014383 --- /dev/null +++ b/tests/ui/dis/panic_builtin_bounds_check.stderr @@ -0,0 +1,38 @@ +OpCapability Shader +OpCapability Float64 +OpCapability Int64 +OpCapability Int16 +OpCapability Int8 +OpCapability ShaderClockKHR +OpExtension "SPV_KHR_non_semantic_info" +OpExtension "SPV_KHR_shader_clock" +%1 = OpExtInstImport "NonSemantic.DebugPrintf" +OpMemoryModel Logical Simple +OpEntryPoint Fragment %2 "main" +OpExecutionMode %2 OriginUpperLeft +%3 = OpString "/n[Rust panicked at $SYSROOT/lib/rustlib/src/rust/library/core/src/panicking.rs:180:5]/n index out of bounds: the len is %u but the index is %u/n in main()/n" +%4 = OpString $SYSROOT/lib/rustlib/src/rust/library/core/src/panicking.rs" +%5 = OpString "$DIR/panic_builtin_bounds_check.rs" +%6 = OpTypeVoid +%7 = OpTypeFunction %6 +%8 = OpTypeBool +%9 = OpTypeInt 32 0 +%10 = OpConstant %9 5 +%11 = OpConstant %9 4 +%2 = OpFunction %6 None %7 +%12 = OpLabel +OpLine %5 25 4 +%13 = OpULessThan %8 %10 %11 +OpNoLine +OpSelectionMerge %14 None +OpBranchConditional %13 %15 %16 +%15 = OpLabel +OpBranch %14 +%16 = OpLabel +OpLine %4 180 4 +%17 = OpExtInst %6 %1 1 %3 %11 %10 +OpNoLine +OpBranch %14 +%14 = OpLabel +OpReturn +OpFunctionEnd