Skip to content

Commit 4de6627

Browse files
committed
black_box: disassemble compiletest
1 parent 84247de commit 4de6627

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

tests/compiletests/ui/lang/core/intrinsics/black_box.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Test black_box intrinsic
22
// build-pass
3+
// compile-flags: -C llvm-args=--disassemble-fn=black_box::disassemble
34

45
#![allow(internal_features)]
56
#![feature(core_intrinsics)]
@@ -9,7 +10,16 @@ use core::hint::black_box;
910
use spirv_std::spirv;
1011

1112
#[spirv(compute(threads(1)))]
12-
pub fn main() {
13+
pub fn main(
14+
#[spirv(descriptor_set = 0, binding = 0, storage_buffer)] out: &mut [u32]
15+
) {
16+
let result = disassemble();
17+
for i in 0..result.len() {
18+
out[i] = result[i];
19+
}
20+
}
21+
22+
pub fn disassemble() -> [u32; 8] {
1323
// Test with various types
1424
let x = 42i32;
1525
let y = black_box(x);
@@ -26,4 +36,6 @@ pub fn main() {
2636
// Test with references
2737
let data = 100u32;
2838
let ref_data = black_box(&data);
39+
40+
[y as u32, f32::to_bits(b), w[0], w[1], w[2], w[3], result, *ref_data]
2941
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,17 @@
11
warning: black_box intrinsic does not prevent optimization in Rust GPU
22

3+
%1 = OpFunction %2 None %3
4+
%4 = OpLabel
5+
OpLine %5 34 17
6+
%6 = OpIAdd %7 %8 %9
7+
OpLine %5 40 5
8+
%10 = OpBitcast %7 %11
9+
OpLine %12 1092 17
10+
%13 = OpBitcast %7 %14
11+
OpLine %5 40 4
12+
%15 = OpCompositeConstruct %2 %10 %13 %16 %17 %18 %19 %6 %20
13+
OpNoLine
14+
OpReturnValue %15
15+
OpFunctionEnd
316
warning: 1 warning emitted
417

0 commit comments

Comments
 (0)