diff --git a/src/writer/spirv/operand.cc b/src/writer/spirv/operand.cc index 1a991ad529..6aa7beaa68 100644 --- a/src/writer/spirv/operand.cc +++ b/src/writer/spirv/operand.cc @@ -54,8 +54,9 @@ uint32_t Operand::length() const { break; case Kind::kString: // SPIR-V always nul-terminates strings. The length is rounded up to a - // multiple of 4 bytes with 0 bytes padding the end. - val = static_cast(ceil((str_val_.length() + 1) / 4.0)); + // multiple of 4 bytes with 0 bytes padding the end. Accounting for the + // nul terminator is why '+ 4u' is used here instead of '+ 3u'. + val = static_cast((str_val_.length() + 4u) >> 2); break; } return val; diff --git a/src/writer/wgsl/generator_impl_constructor_test.cc b/src/writer/wgsl/generator_impl_constructor_test.cc index 44b65d2087..8eba2b17ed 100644 --- a/src/writer/wgsl/generator_impl_constructor_test.cc +++ b/src/writer/wgsl/generator_impl_constructor_test.cc @@ -165,8 +165,10 @@ TEST_F(GeneratorImplTest, EmitConstructor_Type_Mat) { ast::ExpressionList mat_values; for (size_t i = 0; i < 3; i++) { - auto lit1 = std::make_unique(&f32, 1.f + (i * 2)); - auto lit2 = std::make_unique(&f32, 2.f + (i * 2)); + auto lit1 = std::make_unique( + &f32, static_cast(1 + (i * 2))); + auto lit2 = std::make_unique( + &f32, static_cast(2 + (i * 2))); ast::ExpressionList values; values.push_back( @@ -196,9 +198,12 @@ TEST_F(GeneratorImplTest, EmitConstructor_Type_Array) { ast::ExpressionList ary_values; for (size_t i = 0; i < 3; i++) { - auto lit1 = std::make_unique(&f32, 1.f + (i * 3)); - auto lit2 = std::make_unique(&f32, 2.f + (i * 3)); - auto lit3 = std::make_unique(&f32, 3.f + (i * 3)); + auto lit1 = std::make_unique( + &f32, static_cast(1 + (i * 3))); + auto lit2 = std::make_unique( + &f32, static_cast(2 + (i * 3))); + auto lit3 = std::make_unique( + &f32, static_cast(3 + (i * 3))); ast::ExpressionList values; values.push_back(