From 4eeeb4921345b9ae7cd9baa26db03976d755ae51 Mon Sep 17 00:00:00 2001 From: teoxoy <28601907+teoxoy@users.noreply.github.com> Date: Mon, 9 Oct 2023 14:45:35 +0200 Subject: [PATCH] fixup! use LocalVariable init --- src/front/wgsl/lower/mod.rs | 19 +++++++++++-------- tests/out/spv/atomicCompareExchange.spvasm | 2 ++ tests/out/wgsl/atomicCompareExchange.wgsl | 2 ++ 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/front/wgsl/lower/mod.rs b/src/front/wgsl/lower/mod.rs index 89342469b4..83874b485a 100644 --- a/src/front/wgsl/lower/mod.rs +++ b/src/front/wgsl/lower/mod.rs @@ -995,6 +995,7 @@ impl<'source, 'temp> Lowerer<'source, 'temp> { let mut typifier = Typifier::default(); let mut body = self.block( &f.body, + true, StatementContext { local_table: &mut local_table, globals: ctx.globals, @@ -1056,12 +1057,13 @@ impl<'source, 'temp> Lowerer<'source, 'temp> { fn block( &mut self, b: &ast::Block<'source>, + is_fn_body: bool, mut ctx: StatementContext<'source, '_, '_>, ) -> Result> { let mut block = crate::Block::default(); for stmt in b.stmts.iter() { - self.statement(stmt, &mut block, ctx.reborrow())?; + self.statement(stmt, &mut block, is_fn_body, ctx.reborrow())?; } Ok(block) @@ -1071,11 +1073,12 @@ impl<'source, 'temp> Lowerer<'source, 'temp> { &mut self, stmt: &ast::Statement<'source>, block: &mut crate::Block, + is_fn_body: bool, mut ctx: StatementContext<'source, '_, '_>, ) -> Result<(), Error<'source>> { let out = match stmt.kind { ast::StatementKind::Block(ref block) => { - let block = self.block(block, ctx.reborrow())?; + let block = self.block(block, false, ctx.reborrow())?; crate::Statement::Block(block) } ast::StatementKind::LocalDecl(ref decl) => match *decl { @@ -1160,7 +1163,7 @@ impl<'source, 'temp> Lowerer<'source, 'temp> { let (const_initializer, initializer) = { match initializer { Some(init) if ctx.expression_constness.is_const(init) => { - (Some(init), None) + (Some(init), (!is_fn_body).then_some(init)) } Some(init) => (None, Some(init)), None => (None, None), @@ -1210,8 +1213,8 @@ impl<'source, 'temp> Lowerer<'source, 'temp> { self.expression(condition, ctx.as_expression(block, &mut emitter))?; block.extend(emitter.finish(ctx.naga_expressions)); - let accept = self.block(accept, ctx.reborrow())?; - let reject = self.block(reject, ctx.reborrow())?; + let accept = self.block(accept, false, ctx.reborrow())?; + let reject = self.block(reject, false, ctx.reborrow())?; crate::Statement::If { condition, @@ -1256,7 +1259,7 @@ impl<'source, 'temp> Lowerer<'source, 'temp> { } ast::SwitchValue::Default => crate::SwitchValue::Default, }, - body: self.block(&case.body, ctx.reborrow())?, + body: self.block(&case.body, false, ctx.reborrow())?, fall_through: case.fall_through, }) }) @@ -1269,8 +1272,8 @@ impl<'source, 'temp> Lowerer<'source, 'temp> { ref continuing, break_if, } => { - let body = self.block(body, ctx.reborrow())?; - let mut continuing = self.block(continuing, ctx.reborrow())?; + let body = self.block(body, false, ctx.reborrow())?; + let mut continuing = self.block(continuing, false, ctx.reborrow())?; let mut emitter = Emitter::default(); emitter.start(ctx.naga_expressions); diff --git a/tests/out/spv/atomicCompareExchange.spvasm b/tests/out/spv/atomicCompareExchange.spvasm index ffe3171279..d08e3656fd 100644 --- a/tests/out/spv/atomicCompareExchange.spvasm +++ b/tests/out/spv/atomicCompareExchange.spvasm @@ -82,6 +82,7 @@ OpBranch %43 %47 = OpAccessChain %46 %22 %45 %48 = OpAtomicLoad %4 %47 %49 %50 OpStore %29 %48 +OpStore %32 %23 OpBranch %51 %51 = OpLabel OpLoopMerge %52 %54 None @@ -153,6 +154,7 @@ OpBranch %92 %96 = OpAccessChain %95 %78 %94 %97 = OpAtomicLoad %3 %96 %49 %50 OpStore %80 %97 +OpStore %82 %23 OpBranch %98 %98 = OpLabel OpLoopMerge %99 %101 None diff --git a/tests/out/wgsl/atomicCompareExchange.wgsl b/tests/out/wgsl/atomicCompareExchange.wgsl index cb08f0dcd1..f68017028f 100644 --- a/tests/out/wgsl/atomicCompareExchange.wgsl +++ b/tests/out/wgsl/atomicCompareExchange.wgsl @@ -21,6 +21,7 @@ fn test_atomic_compare_exchange_i32_() { let _e6 = i; let _e8 = atomicLoad((&arr_i32_[_e6])); old = _e8; + exchanged = false; loop { let _e12 = exchanged; if !(_e12) { @@ -62,6 +63,7 @@ fn test_atomic_compare_exchange_u32_() { let _e6 = i_1; let _e8 = atomicLoad((&arr_u32_[_e6])); old_1 = _e8; + exchanged_1 = false; loop { let _e12 = exchanged_1; if !(_e12) {