Skip to content

Commit e0d9071

Browse files
eddybLegNeato
authored andcommitted
tests: also test the debugPrintf generated from panics.
1 parent d5a31c1 commit e0d9071

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#![crate_name = "panic_builtin_bounds_check"]
2+
3+
// Test that bounds checking panics get converted to `debugPrintf` correctly.
4+
5+
// build-pass
6+
// compile-flags: -C target-feature=+ext:SPV_KHR_non_semantic_info
7+
// compile-flags: -C llvm-args=--abort-strategy=debug-printf
8+
// compile-flags: -C llvm-args=--disassemble
9+
10+
// FIXME(eddyb) consider using such replacements also for dealing
11+
// with `OpLine` changing all the time (esp. in libcore functions).
12+
//
13+
// normalize-stderr-test "; (SPIR-V|Generator: rspirv|Version: 1\.\d+|Bound: \d+)\n" -> ""
14+
// normalize-stderr-test "OpCapability VulkanMemoryModel\n" -> ""
15+
// normalize-stderr-test "OpSource .*\n" -> ""
16+
// normalize-stderr-test "OpExtension .SPV_KHR_vulkan_memory_model.\n" -> ""
17+
// normalize-stderr-test "OpMemoryModel Logical Vulkan" -> "OpMemoryModel Logical Simple"
18+
19+
// FIXME(eddyb) handle this one in the test runner.
20+
// normalize-stderr-test "\S*/lib/rustlib/" -> "$$SYSROOT/lib/rustlib/"
21+
22+
use spirv_std::spirv;
23+
24+
fn array_bounds_check(x: [u32; 4], i: usize) -> u32 {
25+
x[i]
26+
}
27+
28+
#[spirv(fragment)]
29+
pub fn main() {
30+
array_bounds_check([0, 1, 2, 3], 5);
31+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
OpCapability Shader
2+
OpCapability Float64
3+
OpCapability Int64
4+
OpCapability Int16
5+
OpCapability Int8
6+
OpCapability ShaderClockKHR
7+
OpExtension "SPV_KHR_non_semantic_info"
8+
OpExtension "SPV_KHR_shader_clock"
9+
%1 = OpExtInstImport "NonSemantic.DebugPrintf"
10+
OpMemoryModel Logical Simple
11+
OpEntryPoint Fragment %2 "main"
12+
OpExecutionMode %2 OriginUpperLeft
13+
%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"
14+
%4 = OpString $SYSROOT/lib/rustlib/src/rust/library/core/src/panicking.rs"
15+
%5 = OpString "$DIR/panic_builtin_bounds_check.rs"
16+
%6 = OpTypeVoid
17+
%7 = OpTypeFunction %6
18+
%8 = OpTypeBool
19+
%9 = OpTypeInt 32 0
20+
%10 = OpConstant %9 5
21+
%11 = OpConstant %9 4
22+
%2 = OpFunction %6 None %7
23+
%12 = OpLabel
24+
OpLine %5 25 4
25+
%13 = OpULessThan %8 %10 %11
26+
OpNoLine
27+
OpSelectionMerge %14 None
28+
OpBranchConditional %13 %15 %16
29+
%15 = OpLabel
30+
OpBranch %14
31+
%16 = OpLabel
32+
OpLine %4 180 4
33+
%17 = OpExtInst %6 %1 1 %3 %11 %10
34+
OpNoLine
35+
OpBranch %14
36+
%14 = OpLabel
37+
OpReturn
38+
OpFunctionEnd

0 commit comments

Comments
 (0)