Skip to content

Commit

Permalink
Don't allow pointers in return values.
Browse files Browse the repository at this point in the history
  • Loading branch information
jimblandy committed May 27, 2021
1 parent 424bf72 commit 8968606
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/valid/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,15 @@ impl super::Validator {
}
}

if let Some(ref result) = fun.result {
if !self.types[result.ty.index()]
.flags
.contains(TypeFlags::DATA | TypeFlags::SIZED)
{
return Err(FunctionError::InvalidReturnType(None));
}
}

self.valid_expression_set.clear();
for (handle, expr) in fun.expressions.iter() {
if expr.needs_pre_emit() {
Expand Down
23 changes: 22 additions & 1 deletion tests/wgsl-errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ fn invalid_pointer_use() {
[[group(0), binding(0)]] var<storage> first: Unsized;
[[group(1), binding(0)]] var<storage> second: Unsized;
fn bad_select(which: bool) -> ptr<storage, f32> {
fn bad_select(which: bool) -> f32 {
let ptr = select(&first, &second, which);
return ptr.runtime[0];
}
Expand All @@ -327,4 +327,25 @@ fn invalid_pointer_use() {
})
if function_name == "bad_select"
}

check_validation_error! {
"
[[block]]
struct AFloat {
said_float: f32;
};
[[group(0), binding(0)]]
var<storage> float: [[access(read_write)]] AFloat;
fn return_pointer() -> ptr<storage, f32> {
return &float.said_float;
}
":
Err(naga::valid::ValidationError::Function {
name: function_name,
error: naga::valid::FunctionError::InvalidReturnType(None),
..
})
if function_name == "return_pointer"
}
}

0 comments on commit 8968606

Please sign in to comment.