diff --git a/src/reader/spirv/function.cc b/src/reader/spirv/function.cc index 963a33d274..9c62f9b58b 100644 --- a/src/reader/spirv/function.cc +++ b/src/reader/spirv/function.cc @@ -614,8 +614,11 @@ bool FunctionEmitter::EmitFunctionDeclaration() { [this, &ast_params](const spvtools::opt::Instruction* param) { auto* ast_type = parser_impl_.ConvertType(param->type_id()); if (ast_type != nullptr) { - ast_params.emplace_back(parser_impl_.MakeVariable( - param->result_id(), ast::StorageClass::kNone, ast_type)); + auto ast_param = parser_impl_.MakeVariable( + param->result_id(), ast::StorageClass::kNone, ast_type); + // Parameters are treated as const declarations. + ast_param->set_is_const(true); + ast_params.emplace_back(std::move(ast_param)); // The value is accessible by name. identifier_values_.insert(param->result_id()); } else { diff --git a/src/reader/spirv/function_call_test.cc b/src/reader/spirv/function_call_test.cc index 4eb8288533..934bb5c0c2 100644 --- a/src/reader/spirv/function_call_test.cc +++ b/src/reader/spirv/function_call_test.cc @@ -219,12 +219,12 @@ TEST_F(SpvParserTest, EmitStatement_CallWithParams) { EXPECT_THAT(module_ast_str, HasSubstr(R"(Module{ Function x_50 -> __u32 ( - Variable{ + VariableConst{ x_51 none __u32 } - Variable{ + VariableConst{ x_52 none __u32 diff --git a/src/reader/spirv/function_decl_test.cc b/src/reader/spirv/function_decl_test.cc index 20e5b1b199..61427260a4 100644 --- a/src/reader/spirv/function_decl_test.cc +++ b/src/reader/spirv/function_decl_test.cc @@ -104,17 +104,17 @@ TEST_F(SpvParserTest, EmitFunctionDeclaration_MixedParamTypes) { EXPECT_THAT(p->module().to_str(), HasSubstr(R"( Function x_100 -> __void ( - Variable{ + VariableConst{ a none __u32 } - Variable{ + VariableConst{ b none __f32 } - Variable{ + VariableConst{ c none __i32 @@ -143,17 +143,17 @@ TEST_F(SpvParserTest, EmitFunctionDeclaration_GenerateParamNames) { EXPECT_THAT(p->module().to_str(), HasSubstr(R"( Function x_100 -> __void ( - Variable{ + VariableConst{ x_14 none __u32 } - Variable{ + VariableConst{ x_15 none __f32 } - Variable{ + VariableConst{ x_16 none __i32 diff --git a/src/reader/spirv/parser_impl_function_decl_test.cc b/src/reader/spirv/parser_impl_function_decl_test.cc index 37af744377..0d0c826384 100644 --- a/src/reader/spirv/parser_impl_function_decl_test.cc +++ b/src/reader/spirv/parser_impl_function_decl_test.cc @@ -293,17 +293,17 @@ TEST_F(SpvParserTest, EmitFunctions_MixedParamTypes) { EXPECT_THAT(module_ast, HasSubstr(R"( Function mixed_params -> __void ( - Variable{ + VariableConst{ a none __u32 } - Variable{ + VariableConst{ b none __f32 } - Variable{ + VariableConst{ c none __i32 @@ -332,17 +332,17 @@ TEST_F(SpvParserTest, EmitFunctions_GenerateParamNames) { EXPECT_THAT(module_ast, HasSubstr(R"( Function mixed_params -> __void ( - Variable{ + VariableConst{ x_14 none __u32 } - Variable{ + VariableConst{ x_15 none __f32 } - Variable{ + VariableConst{ x_16 none __i32