Skip to content

Commit 17da613

Browse files
committed
test: [naga wgsl-in] add tests for @must_use
1 parent 150a204 commit 17da613

File tree

2 files changed

+73
-9
lines changed

2 files changed

+73
-9
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
fn main() {}
2+
3+
@must_use
4+
fn use_me(x: i32) -> i32 {
5+
return 10 + x;
6+
}
7+
8+
fn constant_short_circuited_expression() -> bool {
9+
return false && 0 != use_me(0);
10+
}
11+
12+
fn constant_skipped_block() -> i32 {
13+
if(false) {
14+
return use_me(-1);
15+
}
16+
return -1;
17+
}
18+
19+
fn assignment_only() -> i32 {
20+
let unused = use_me(-1);
21+
return -1;
22+
}
23+
24+
fn assignment_and_constant_skipped_block() -> i32 {
25+
let unused = use_me(-1);
26+
if(false) {
27+
return unused;
28+
}
29+
return -1;
30+
}
31+
32+
fn assignment_and_maybe_skipped_block(skip: bool) -> i32 {
33+
let unused = use_me(-1);
34+
if(skip) {
35+
return unused;
36+
}
37+
return -1;
38+
}
39+
40+
fn assign_and_use_before_constant_return() -> i32 {
41+
let called_a = use_me_10();
42+
let used_a = 1 + called_a;
43+
return 2;
44+
}

naga/tests/in/must-use.wgsl

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,35 @@
1-
@compute @workgroup_size(1)
21
fn main() {}
32

43
@must_use
5-
fn use_me(x: i32) -> i32 {
6-
return 10 + x;
4+
fn use_me_10() -> i32 { return 10; }
5+
6+
@must_use
7+
fn use_me_false() -> bool { return false; }
8+
9+
fn use_return() -> i32 {
10+
return use_me_10();
11+
}
12+
13+
fn use_expression() -> bool {
14+
return use_me_10() == 10;
15+
}
16+
17+
18+
fn assign_and_return() -> i32 {
19+
let called_a = use_me_10();
20+
return called_a;
21+
}
22+
23+
fn assign_and_use_before_return() -> i32 {
24+
let called_a = use_me_10();
25+
let used_a = 1 + called_a;
26+
return used_a;
727
}
828

9-
fn useful(
10-
m: i32,
11-
) -> i32 {
12-
var q = use_me(m);
13-
q += m;
14-
return q;
29+
fn use_in_condition_expression() -> i32 {
30+
if(use_me_false()) {
31+
return 1;
32+
} else {
33+
return 2;
34+
}
1535
}

0 commit comments

Comments
 (0)