aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorThomas Schwinge <thomas@codesourcery.com>2023-04-12 11:38:58 +0200
committerThomas Schwinge <thomas@codesourcery.com>2023-04-14 11:57:11 +0200
commit41c7e1d0a707f97327f097022e9e6fa7f6f13533 (patch)
treeb6103ed0c8c28925e6e1bc3cd30582b829b45ded /gcc
parent37d4fa770ff751381db8f4fe225bf9e4ec22be56 (diff)
downloadgcc-41c7e1d0a707f97327f097022e9e6fa7f6f13533.zip
gcc-41c7e1d0a707f97327f097022e9e6fa7f6f13533.tar.gz
gcc-41c7e1d0a707f97327f097022e9e6fa7f6f13533.tar.bz2
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'.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/rust/backend/rust-compile-base.cc3
-rw-r--r--gcc/rust/rust-lang.cc3
2 files changed, 6 insertions, 0 deletions
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;
diff --git a/gcc/rust/rust-lang.cc b/gcc/rust/rust-lang.cc
index f353229..9f1a914 100644
--- a/gcc/rust/rust-lang.cc
+++ b/gcc/rust/rust-lang.cc
@@ -38,6 +38,7 @@
#include "rust-privacy-ctx.h"
#include "rust-ast-resolve-item.h"
#include "rust-optional.h"
+#include "stringpool.h"
#include <mpfr.h>
// note: header files must be in this order or else forward declarations don't
@@ -124,6 +125,8 @@ grs_langhook_init (void)
whether char is signed. */
build_common_tree_nodes (false);
+ main_identifier_node = get_identifier ("main");
+
// Builds built-ins for middle-end after all front-end built-ins are already
// instantiated
build_common_builtin_nodes ();