Skip to content

Commit

Permalink
[naga] Restore return statement at end of functions without return ty…
Browse files Browse the repository at this point in the history
…pes (#7021)
  • Loading branch information
jamienicol authored Jan 29, 2025
1 parent e0ebd1b commit 6c8d0b0
Show file tree
Hide file tree
Showing 229 changed files with 629 additions and 33 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ By @brodycj in [#6924](https://github.com/gfx-rs/wgpu/pull/6924).

### Bug Fixes

#### Naga

- Fix some instances of functions which have a return type but don't return a value being incorrectly validated. By @jamienicol in [#7013](https://github.com/gfx-rs/wgpu/pull/7013).

#### General

- Avoid overflow in query set bounds check validation. By @ErichDonGubler in [#6933](https://github.com/gfx-rs/wgpu/pull/6933).
Expand Down
4 changes: 1 addition & 3 deletions naga/src/front/glsl/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1031,9 +1031,7 @@ impl Frontend {
result: Option<FunctionResult>,
meta: Span,
) {
if result.is_some() {
ensure_block_returns(&mut ctx.body);
}
ensure_block_returns(&mut ctx.body);

let void = result.is_none();

Expand Down
4 changes: 1 addition & 3 deletions naga/src/front/wgsl/lower/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1307,9 +1307,7 @@ impl<'source, 'temp> Lowerer<'source, 'temp> {
global_expression_kind_tracker: ctx.global_expression_kind_tracker,
};
let mut body = self.block(&f.body, false, &mut stmt_ctx)?;
if function.result.is_some() {
ensure_block_returns(&mut body);
}
ensure_block_returns(&mut body);

function.body = body;
function.named_expressions = named_expressions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
void main() {
int phony = ivec4(bitfieldExtract(int(12u), 0, 8), bitfieldExtract(int(12u), 8, 8), bitfieldExtract(int(12u), 16, 8), bitfieldExtract(int(12u), 24, 8))[2];
uint phony_1 = uvec4(bitfieldExtract(12u, 0, 8), bitfieldExtract(12u, 8, 8), bitfieldExtract(12u, 16, 8), bitfieldExtract(12u, 24, 8)).y;
return;
}

5 changes: 5 additions & 0 deletions naga/tests/out/glsl/access.assign_through_ptr.Compute.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,12 @@ float test_arr_as_arg(float a[5][10]) {

void assign_through_ptr_fn(inout uint p) {
p = 42u;
return;
}

void assign_array_through_ptr_fn(inout vec4 foo_2[2]) {
foo_2 = vec4[2](vec4(1.0), vec4(2.0));
return;
}

uint fetch_arg_ptr_member(inout AssignToMember p_1) {
Expand All @@ -57,6 +59,7 @@ uint fetch_arg_ptr_member(inout AssignToMember p_1) {

void assign_to_arg_ptr_member(inout AssignToMember p_2) {
p_2.x = 10u;
return;
}

uint fetch_arg_ptr_array_element(inout uint p_3[4]) {
Expand All @@ -66,6 +69,7 @@ uint fetch_arg_ptr_array_element(inout uint p_3[4]) {

void assign_to_arg_ptr_array_element(inout uint p_4[4]) {
p_4[1] = 10u;
return;
}

bool index_ptr(bool value) {
Expand Down Expand Up @@ -110,5 +114,6 @@ void main() {
vec4 arr[2] = vec4[2](vec4(6.0), vec4(7.0));
assign_through_ptr_fn(val);
assign_array_through_ptr_fn(arr);
return;
}

Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,12 @@ float test_arr_as_arg(float a[5][10]) {

void assign_through_ptr_fn(inout uint p) {
p = 42u;
return;
}

void assign_array_through_ptr_fn(inout vec4 foo_2[2]) {
foo_2 = vec4[2](vec4(1.0), vec4(2.0));
return;
}

uint fetch_arg_ptr_member(inout AssignToMember p_1) {
Expand All @@ -57,6 +59,7 @@ uint fetch_arg_ptr_member(inout AssignToMember p_1) {

void assign_to_arg_ptr_member(inout AssignToMember p_2) {
p_2.x = 10u;
return;
}

uint fetch_arg_ptr_array_element(inout uint p_3[4]) {
Expand All @@ -66,6 +69,7 @@ uint fetch_arg_ptr_array_element(inout uint p_3[4]) {

void assign_to_arg_ptr_array_element(inout uint p_4[4]) {
p_4[1] = 10u;
return;
}

bool index_ptr(bool value) {
Expand Down Expand Up @@ -112,5 +116,6 @@ void main() {
uint _e1 = fetch_arg_ptr_member(s1_);
assign_to_arg_ptr_array_element(a1_);
uint _e3 = fetch_arg_ptr_array_element(a1_);
return;
}

4 changes: 4 additions & 0 deletions naga/tests/out/glsl/access.foo_frag.Fragment.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,12 @@ float test_arr_as_arg(float a[5][10]) {

void assign_through_ptr_fn(inout uint p) {
p = 42u;
return;
}

void assign_array_through_ptr_fn(inout vec4 foo_2[2]) {
foo_2 = vec4[2](vec4(1.0), vec4(2.0));
return;
}

uint fetch_arg_ptr_member(inout AssignToMember p_1) {
Expand All @@ -67,6 +69,7 @@ uint fetch_arg_ptr_member(inout AssignToMember p_1) {

void assign_to_arg_ptr_member(inout AssignToMember p_2) {
p_2.x = 10u;
return;
}

uint fetch_arg_ptr_array_element(inout uint p_3[4]) {
Expand All @@ -76,6 +79,7 @@ uint fetch_arg_ptr_array_element(inout uint p_3[4]) {

void assign_to_arg_ptr_array_element(inout uint p_4[4]) {
p_4[1] = 10u;
return;
}

bool index_ptr(bool value) {
Expand Down
6 changes: 6 additions & 0 deletions naga/tests/out/glsl/access.foo_vert.Vertex.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ void test_matrix_within_struct_accesses() {
int _e85 = idx;
int _e87 = idx;
t.m[_e85][_e87] = 40.0;
return;
}

void test_matrix_within_array_within_struct_accesses() {
Expand Down Expand Up @@ -112,6 +113,7 @@ void test_matrix_within_array_within_struct_accesses() {
int _e100 = idx_1;
int _e102 = idx_1;
t_1.am[0][_e100][_e102] = 40.0;
return;
}

float read_from_private(inout float foo_1) {
Expand All @@ -125,10 +127,12 @@ float test_arr_as_arg(float a[5][10]) {

void assign_through_ptr_fn(inout uint p) {
p = 42u;
return;
}

void assign_array_through_ptr_fn(inout vec4 foo_2[2]) {
foo_2 = vec4[2](vec4(1.0), vec4(2.0));
return;
}

uint fetch_arg_ptr_member(inout AssignToMember p_1) {
Expand All @@ -138,6 +142,7 @@ uint fetch_arg_ptr_member(inout AssignToMember p_1) {

void assign_to_arg_ptr_member(inout AssignToMember p_2) {
p_2.x = 10u;
return;
}

uint fetch_arg_ptr_array_element(inout uint p_3[4]) {
Expand All @@ -147,6 +152,7 @@ uint fetch_arg_ptr_array_element(inout uint p_3[4]) {

void assign_to_arg_ptr_array_element(inout uint p_4[4]) {
p_4[1] = 10u;
return;
}

bool index_ptr(bool value) {
Expand Down
1 change: 1 addition & 0 deletions naga/tests/out/glsl/array-in-ctor.cs_main.Compute.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ layout(std430) readonly buffer Ah_block_0Compute { Ah _group_0_binding_0_cs; };

void main() {
Ah ah_1 = _group_0_binding_0_cs;
return;
}

1 change: 1 addition & 0 deletions naga/tests/out/glsl/atomicOps.cs_main.Compute.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -127,5 +127,6 @@ void main() {
int _e295 = atomicExchange(workgroup_atomic_arr[1], 1);
uint _e299 = atomicExchange(workgroup_struct.atomic_scalar, 1u);
int _e304 = atomicExchange(workgroup_struct.atomic_arr[1], 1);
return;
}

1 change: 1 addition & 0 deletions naga/tests/out/glsl/atomicTexture.cs_main.Compute.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ void main() {
imageAtomicAnd(_group_0_binding_1_cs, ivec2(0, 0), 1);
imageAtomicOr(_group_0_binding_1_cs, ivec2(0, 0), 1);
imageAtomicXor(_group_0_binding_1_cs, ivec2(0, 0), 1);
return;
}

1 change: 1 addition & 0 deletions naga/tests/out/glsl/bitcast.main.Compute.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,6 @@ void main() {
f3_ = intBitsToFloat(_e41);
ivec4 _e43 = i4_;
f4_ = intBitsToFloat(_e43);
return;
}

1 change: 1 addition & 0 deletions naga/tests/out/glsl/bits.main.Compute.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -129,5 +129,6 @@ void main() {
u3_ = bitfieldReverse(_e168);
uvec4 _e170 = u4_;
u4_ = bitfieldReverse(_e170);
return;
}

1 change: 1 addition & 0 deletions naga/tests/out/glsl/boids.main.Compute.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -150,5 +150,6 @@ void main() {
_group_0_binding_2_cs.particles[index].pos = _e174;
vec2 _e179 = vVel;
_group_0_binding_2_cs.particles[index].vel = _e179;
return;
}

Original file line number Diff line number Diff line change
Expand Up @@ -58,22 +58,27 @@ vec4 test_textureLoad_multisampled_2d(ivec2 coords_5, int _sample) {

void test_textureStore_1d(int coords_10, vec4 value) {
imageStore(_group_0_binding_8_fs, coords_10, value);
return;
}

void test_textureStore_2d(ivec2 coords_11, vec4 value_1) {
imageStore(_group_0_binding_9_fs, coords_11, value_1);
return;
}

void test_textureStore_2d_array_u(ivec2 coords_12, uint array_index, vec4 value_2) {
imageStore(_group_0_binding_10_fs, ivec3(coords_12, array_index), value_2);
return;
}

void test_textureStore_2d_array_s(ivec2 coords_13, int array_index_1, vec4 value_3) {
imageStore(_group_0_binding_10_fs, ivec3(coords_13, array_index_1), value_3);
return;
}

void test_textureStore_3d(ivec3 coords_14, vec4 value_4) {
imageStore(_group_0_binding_11_fs, coords_14, value_4);
return;
}

void main() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,27 @@ vec4 test_textureLoad_multisampled_2d(ivec2 coords_5, int _sample) {

void test_textureStore_1d(int coords_10, vec4 value) {
imageStore(_group_0_binding_8_fs, coords_10, value);
return;
}

void test_textureStore_2d(ivec2 coords_11, vec4 value_1) {
imageStore(_group_0_binding_9_fs, coords_11, value_1);
return;
}

void test_textureStore_2d_array_u(ivec2 coords_12, uint array_index, vec4 value_2) {
imageStore(_group_0_binding_10_fs, ivec3(coords_12, array_index), value_2);
return;
}

void test_textureStore_2d_array_s(ivec2 coords_13, int array_index_1, vec4 value_3) {
imageStore(_group_0_binding_10_fs, ivec3(coords_13, array_index_1), value_3);
return;
}

void test_textureStore_3d(ivec3 coords_14, vec4 value_4) {
imageStore(_group_0_binding_11_fs, coords_14, value_4);
return;
}

void main() {
Expand Down
5 changes: 5 additions & 0 deletions naga/tests/out/glsl/break-if.main.Compute.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ void breakIfEmpty() {
}
loop_init = false;
}
return;
}

void breakIfEmptyBody(bool a) {
Expand All @@ -34,6 +35,7 @@ void breakIfEmptyBody(bool a) {
}
loop_init_1 = false;
}
return;
}

void breakIf(bool a_1) {
Expand All @@ -52,6 +54,7 @@ void breakIf(bool a_1) {
bool _e2 = d;
e = (a_1 != _e2);
}
return;
}

void breakIfSeparateVariable() {
Expand All @@ -68,8 +71,10 @@ void breakIfSeparateVariable() {
uint _e3 = counter;
counter = (_e3 + 1u);
}
return;
}

void main() {
return;
}

8 changes: 8 additions & 0 deletions naga/tests/out/glsl/const-exprs.main.Compute.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,17 @@ const bvec2 compare_vec = bvec2(true, false);

void swizzle_of_compose() {
ivec4 out_ = ivec4(4, 3, 2, 1);
return;
}

void index_of_compose() {
int out_1 = 2;
return;
}

void compose_three_deep() {
int out_2 = 6;
return;
}

void non_constant_initializers() {
Expand All @@ -48,18 +51,22 @@ void non_constant_initializers() {
int _e10 = y;
int _e11 = z;
out_3 = ivec4(_e8, _e9, _e10, _e11);
return;
}

void splat_of_constant() {
ivec4 out_4 = ivec4(-4, -4, -4, -4);
return;
}

void compose_of_constant() {
ivec4 out_5 = ivec4(-4, -4, -4, -4);
return;
}

void compose_of_splat() {
vec4 x_1 = vec4(2.0, 1.0, 1.0, 1.0);
return;
}

uint map_texture_kind(int texture_kind) {
Expand Down Expand Up @@ -87,5 +94,6 @@ void main() {
splat_of_constant();
compose_of_constant();
compose_of_splat();
return;
}

1 change: 1 addition & 0 deletions naga/tests/out/glsl/constructors.main.Compute.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,6 @@ void main() {
int cit2_[4] = int[4](0, 1, 2, 3);
uvec2 ic4_ = uvec2(0u, 0u);
mat2x3 ic5_ = mat2x3(vec3(0.0, 0.0, 0.0), vec3(0.0, 0.0, 0.0));
return;
}

Loading

0 comments on commit 6c8d0b0

Please sign in to comment.