Skip to content

Commit

Permalink
test: [naga wgsl-in] add tests for @must_use
Browse files Browse the repository at this point in the history
  • Loading branch information
turbocrime committed Dec 22, 2024
1 parent 150a204 commit 201ce67
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 9 deletions.
44 changes: 44 additions & 0 deletions naga/tests/in/must-use-questionable.wgsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
fn main() {}

@must_use
fn use_me(x: i32) -> i32 {
return 10 + x;
}

fn constant_short_circuited_expression() -> bool {
return false && 0 != use_me(0);
}

fn constant_skipped_block() -> i32 {
if(false) {
return use_me(-1);
}
return -1;
}

fn assignment_only() -> i32 {
let unused = use_me(-1);
return -1;
}

fn assignment_and_constant_skipped_block() -> i32 {
let unused = use_me(-1);
if(false) {
return unused;
}
return -1;
}

fn assignment_and_maybe_skipped_block(skip: bool) -> i32 {
let unused = use_me(-1);
if(skip) {
return unused;
}
return -1;
}

fn assign_and_use_before_constant_return() -> i32 {
let called_a = use_me(-1);
let used_a = 1 + called_a;
return 2;
}
48 changes: 39 additions & 9 deletions naga/tests/in/must-use.wgsl
Original file line number Diff line number Diff line change
@@ -1,15 +1,45 @@
@compute @workgroup_size(1)
fn main() {}

@must_use
fn use_me(x: i32) -> i32 {
return 10 + x;
fn use_me_10() -> i32 { return 10; }

@must_use
fn use_me_false() -> bool { return false; }

fn use_return() -> i32 {
return use_me_10();
}

fn unused_deep() -> i32 {
use_return();
return -1;
}

fn use_in_expression() -> bool {
return use_me_10() == 10;
}

fn assign_and_return() -> i32 {
let called_a = use_me_10();
return called_a;
}

fn assign_and_use_before_return() -> i32 {
let called_a = use_me_10();
let used_a = 1 + called_a;
return used_a;
}

fn assign_and_clobber() -> i32 {
var clobber_me = use_me_10();
clobber_me = 1000;
return clobber_me;
}

fn useful(
m: i32,
) -> i32 {
var q = use_me(m);
q += m;
return q;
fn use_in_condition_expression() -> i32 {
if(use_me_false()) {
return 1;
} else {
return 2;
}
}

0 comments on commit 201ce67

Please sign in to comment.