From 41c7e1d0a707f97327f097022e9e6fa7f6f13533 Mon Sep 17 00:00:00 2001 From: Thomas Schwinge Date: Wed, 12 Apr 2023 11:38:58 +0200 Subject: Rust: Make 'tree'-level 'MAIN_NAME_P' work 'gcc/tree.h': #define main_identifier_node global_trees[TI_MAIN_IDENTIFIER] #define MAIN_NAME_P(NODE) \ (IDENTIFIER_NODE_CHECK (NODE) == main_identifier_node) ..., which is not initialized by default, but has to be set up by every front end individually. 'MAIN_NAME_P' enables certain code optimizations, but is especially also relevant for back ends that emit additional program entry setup code for 'main'. gcc/rust/ * backend/rust-compile-base.cc (HIRCompileBase::compile_function): Handle 'main' specially. * rust-lang.cc (grs_langhook_init): Initialize 'main_identifier_node'. --- gcc/rust/backend/rust-compile-base.cc | 3 +++ 1 file changed, 3 insertions(+) (limited to 'gcc/rust/backend') diff --git a/gcc/rust/backend/rust-compile-base.cc b/gcc/rust/backend/rust-compile-base.cc index 9650d1a..9b8a793 100644 --- a/gcc/rust/backend/rust-compile-base.cc +++ b/gcc/rust/backend/rust-compile-base.cc @@ -523,6 +523,9 @@ HIRCompileBase::compile_function ( // we don't mangle the main fn since we haven't implemented the main shim bool is_main_fn = fn_name.compare ("main") == 0; + if (is_main_fn) + /* So that 'MAIN_NAME_P' works. */ + ir_symbol_name = fn_name; std::string asm_name = fn_name; unsigned int flags = 0; -- cgit v1.1 From 4e95a9117487c07f876f913499cb9954b6cd7d54 Mon Sep 17 00:00:00 2001 From: Thomas Schwinge Date: Fri, 14 Apr 2023 11:57:21 +0200 Subject: Revert "Rust: Make 'tree'-level 'MAIN_NAME_P' work" This reverts commit 41c7e1d0a707f97327f097022e9e6fa7f6f13533. --- gcc/rust/backend/rust-compile-base.cc | 3 --- 1 file changed, 3 deletions(-) (limited to 'gcc/rust/backend') diff --git a/gcc/rust/backend/rust-compile-base.cc b/gcc/rust/backend/rust-compile-base.cc index 9b8a793..9650d1a 100644 --- a/gcc/rust/backend/rust-compile-base.cc +++ b/gcc/rust/backend/rust-compile-base.cc @@ -523,9 +523,6 @@ HIRCompileBase::compile_function ( // we don't mangle the main fn since we haven't implemented the main shim bool is_main_fn = fn_name.compare ("main") == 0; - if (is_main_fn) - /* So that 'MAIN_NAME_P' works. */ - ir_symbol_name = fn_name; std::string asm_name = fn_name; unsigned int flags = 0; -- cgit v1.1 From 705de6d54ca95b8277a15fe9a2255af6168ae086 Mon Sep 17 00:00:00 2001 From: Thomas Schwinge Date: Wed, 12 Apr 2023 11:47:01 +0200 Subject: Rust: Make 'tree'-level 'MAIN_NAME_P' work 'gcc/tree.h': #define main_identifier_node global_trees[TI_MAIN_IDENTIFIER] #define MAIN_NAME_P(NODE) \ (IDENTIFIER_NODE_CHECK (NODE) == main_identifier_node) ..., which is not initialized by default, but has to be set up by every front end individually. 'MAIN_NAME_P' enables certain code optimizations, but is especially also relevant for back ends that emit additional program entry setup code for 'main'. gcc/rust/ * backend/rust-compile-base.cc (HIRCompileBase::compile_function): For 'main', initialize 'main_identifier_node'. --- gcc/rust/backend/rust-compile-base.cc | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'gcc/rust/backend') diff --git a/gcc/rust/backend/rust-compile-base.cc b/gcc/rust/backend/rust-compile-base.cc index 9650d1a..19bf242 100644 --- a/gcc/rust/backend/rust-compile-base.cc +++ b/gcc/rust/backend/rust-compile-base.cc @@ -523,6 +523,12 @@ HIRCompileBase::compile_function ( // we don't mangle the main fn since we haven't implemented the main shim bool is_main_fn = fn_name.compare ("main") == 0; + if (is_main_fn) + { + rust_assert (!main_identifier_node); + /* So that 'MAIN_NAME_P' works. */ + main_identifier_node = get_identifier (ir_symbol_name.c_str ()); + } std::string asm_name = fn_name; unsigned int flags = 0; -- cgit v1.1