From: Thomas Schwinge Date: Wed, 12 Apr 2023 09:47:01 +0000 (+0200) Subject: Rust: Make 'tree'-level 'MAIN_NAME_P' work X-Git-Tag: basepoints/gcc-16~7074 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5f9e88211c6ad939cfec017a66e663d686c9c3ab;p=thirdparty%2Fgcc.git 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'. --- diff --git a/gcc/rust/backend/rust-compile-base.cc b/gcc/rust/backend/rust-compile-base.cc index 984492f6607c..4d6f0275b004 100644 --- a/gcc/rust/backend/rust-compile-base.cc +++ b/gcc/rust/backend/rust-compile-base.cc @@ -657,6 +657,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;