From b1afef95601fd2f0323dd508a171267ff04f755b Mon Sep 17 00:00:00 2001 From: Philip Herron Date: Wed, 2 Apr 2025 16:16:47 +0100 Subject: gccrs: Fix ICE when there are 2 functions named main We need to setup the main_identifier_node for MAIN_DECL_P checks in the middle-end. But it is valid to have a main function/method on impl blocks. So we need to flag if this is a "root" item or not, which is one that is jsut an HIR::Function on part of the Crate::items as oppposed to a HIR::Function which is part of an HIR::ImplBlock as part of the HIR::Crate. Some small cleanups have been added here too. Fixes Rust-GCC#3648 gcc/rust/ChangeLog: * backend/rust-compile-base.cc: new flag is_root_item * backend/rust-compile-base.h: update prototype * backend/rust-compile-implitem.cc (CompileTraitItem::visit): update call * backend/rust-compile-implitem.h: remove old debug internal error * backend/rust-compile-item.cc (CompileItem::visit): update call * backend/rust-compile-item.h: remove old debug * backend/rust-compile-resolve-path.cc (HIRCompileBase::query_compile): update calls * backend/rust-compile.cc: likewise * typecheck/rust-hir-trait-resolve.cc (TraitResolver::resolve_path_to_trait): remove assertion and error gcc/testsuite/ChangeLog: * rust/compile/issue-3648.rs: New test. Signed-off-by: Philip Herron --- gcc/rust/backend/rust-compile-base.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'gcc/rust/backend/rust-compile-base.cc') diff --git a/gcc/rust/backend/rust-compile-base.cc b/gcc/rust/backend/rust-compile-base.cc index fdbca7f..b6bee8f 100644 --- a/gcc/rust/backend/rust-compile-base.cc +++ b/gcc/rust/backend/rust-compile-base.cc @@ -663,7 +663,7 @@ get_abi (const AST::AttrVec &outer_attrs, tree HIRCompileBase::compile_function ( - const std::string &fn_name, HIR::SelfParam &self_param, + bool is_root_item, const std::string &fn_name, HIR::SelfParam &self_param, std::vector &function_params, const HIR::FunctionQualifiers &qualifiers, HIR::Visibility &visibility, AST::AttrVec &outer_attrs, location_t locus, HIR::BlockExpr *function_body, @@ -674,7 +674,7 @@ HIRCompileBase::compile_function ( = canonical_path.get () + fntype->subst_as_string (); // we don't mangle the main fn since we haven't implemented the main shim - bool is_main_fn = fn_name.compare ("main") == 0; + bool is_main_fn = fn_name.compare ("main") == 0 && is_root_item; if (is_main_fn) { rust_assert (!main_identifier_node); -- cgit v1.1