-
Notifications
You must be signed in to change notification settings - Fork 964
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: [naga wgsl-in] add tests for
@must_use
- Loading branch information
1 parent
150a204
commit 201ce67
Showing
2 changed files
with
83 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |