aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/rust-gcc.cc
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2022-02-10 17:08:15 +0000
committerGitHub <noreply@github.com>2022-02-10 17:08:15 +0000
commite2823b6747b36362387e5b26e8792f06185d7de8 (patch)
treea1c1a61fd3031416ca3bc600212cd13e51f727b8 /gcc/rust/rust-gcc.cc
parentf6ba472caf42db1f5f2f98b73afccf448b36c322 (diff)
parent1b487d72cd2ba46671f5a1bcc20970f2dad1b759 (diff)
downloadgcc-e2823b6747b36362387e5b26e8792f06185d7de8.zip
gcc-e2823b6747b36362387e5b26e8792f06185d7de8.tar.gz
gcc-e2823b6747b36362387e5b26e8792f06185d7de8.tar.bz2
Merge #917
917: remove tree addressable context during type checking r=philberty a=philberty We can reuse more C front-end code c_mark_addressable can be used instead of trying to track TREE_ADDRESSABLE as part of type-checking. This also pulls the GCC::Backend::address_expression to be part of the HIRCompileBase class during code-generation. Co-authored-by: Philip Herron <philip.herron@embecosm.com>
Diffstat (limited to 'gcc/rust/rust-gcc.cc')
-rw-r--r--gcc/rust/rust-gcc.cc249
1 files changed, 5 insertions, 244 deletions
diff --git a/gcc/rust/rust-gcc.cc b/gcc/rust/rust-gcc.cc
index 62c9d80..86a4106 100644
--- a/gcc/rust/rust-gcc.cc
+++ b/gcc/rust/rust-gcc.cc
@@ -231,8 +231,6 @@ public:
tree function_code_expression (tree, Location);
- tree address_expression (tree, Location);
-
tree struct_field_expression (tree, size_t, Location);
tree compound_expression (tree, tree, Location);
@@ -312,35 +310,16 @@ public:
void global_variable_set_init (Bvariable *, tree);
- Bvariable *local_variable (tree, const std::string &, tree, Bvariable *, bool,
+ Bvariable *local_variable (tree, const std::string &, tree, Bvariable *,
Location);
- Bvariable *parameter_variable (tree, const std::string &, tree, bool,
- Location);
+ Bvariable *parameter_variable (tree, const std::string &, tree, Location);
Bvariable *static_chain_variable (tree, const std::string &, tree, Location);
Bvariable *temporary_variable (tree, tree, tree, tree, bool, Location,
tree *);
- Bvariable *implicit_variable (const std::string &, const std::string &, tree,
- bool, bool, bool, int64_t);
-
- void implicit_variable_set_init (Bvariable *, const std::string &, tree, bool,
- bool, bool, tree);
-
- Bvariable *implicit_variable_reference (const std::string &,
- const std::string &, tree);
-
- Bvariable *immutable_struct (const std::string &, const std::string &, bool,
- bool, tree, Location);
-
- void immutable_struct_set_init (Bvariable *, const std::string &, bool, bool,
- tree, Location, tree);
-
- Bvariable *immutable_struct_reference (const std::string &,
- const std::string &, tree, Location);
-
// Labels.
tree label (tree, const std::string &name, Location);
@@ -1338,17 +1317,6 @@ Gcc_backend::function_code_expression (tree func, Location location)
return ret;
}
-// Get the address of an expression.
-
-tree
-Gcc_backend::address_expression (tree expr, Location location)
-{
- if (expr == error_mark_node)
- return this->error_expression ();
-
- return build_fold_addr_expr_loc (location.gcc_location (), expr);
-}
-
// Return an expression for the field at INDEX in BSTRUCT.
tree
@@ -2495,7 +2463,7 @@ Gcc_backend::global_variable_set_init (Bvariable *var, tree expr_tree)
Bvariable *
Gcc_backend::local_variable (tree function, const std::string &name,
tree type_tree, Bvariable *decl_var,
- bool is_address_taken, Location location)
+ Location location)
{
if (type_tree == error_mark_node)
return this->error_variable ();
@@ -2503,8 +2471,7 @@ Gcc_backend::local_variable (tree function, const std::string &name,
get_identifier_from_string (name), type_tree);
DECL_CONTEXT (decl) = function;
TREE_USED (decl) = 1;
- if (is_address_taken)
- TREE_ADDRESSABLE (decl) = 1;
+
if (decl_var != NULL)
{
DECL_HAS_VALUE_EXPR_P (decl) = 1;
@@ -2518,8 +2485,7 @@ Gcc_backend::local_variable (tree function, const std::string &name,
Bvariable *
Gcc_backend::parameter_variable (tree function, const std::string &name,
- tree type_tree, bool is_address_taken,
- Location location)
+ tree type_tree, Location location)
{
if (type_tree == error_mark_node)
return this->error_variable ();
@@ -2528,8 +2494,6 @@ Gcc_backend::parameter_variable (tree function, const std::string &name,
DECL_CONTEXT (decl) = function;
DECL_ARG_TYPE (decl) = type_tree;
TREE_USED (decl) = 1;
- if (is_address_taken)
- TREE_ADDRESSABLE (decl) = 1;
rust_preserve_from_gc (decl);
return new Bvariable (decl);
}
@@ -2633,209 +2597,6 @@ Gcc_backend::temporary_variable (tree fndecl, tree bind_tree, tree type_tree,
return new Bvariable (var);
}
-// Create an implicit variable that is compiler-defined. This is used when
-// generating GC root variables and storing the values of a slice initializer.
-
-Bvariable *
-Gcc_backend::implicit_variable (const std::string &name,
- const std::string &asm_name, tree type_tree,
- bool is_hidden, bool is_constant,
- bool is_common, int64_t alignment)
-{
- if (type_tree == error_mark_node)
- return this->error_variable ();
-
- tree decl = build_decl (BUILTINS_LOCATION, VAR_DECL,
- get_identifier_from_string (name), type_tree);
- DECL_EXTERNAL (decl) = 0;
- TREE_PUBLIC (decl) = !is_hidden;
- TREE_STATIC (decl) = 1;
- TREE_USED (decl) = 1;
- DECL_ARTIFICIAL (decl) = 1;
- if (is_common)
- {
- DECL_COMMON (decl) = 1;
-
- // When the initializer for one implicit_variable refers to another,
- // it needs to know the visibility of the referenced struct so that
- // compute_reloc_for_constant will return the right value. On many
- // systems calling make_decl_one_only will mark the decl as weak,
- // which will change the return value of compute_reloc_for_constant.
- // We can't reliably call make_decl_one_only yet, because we don't
- // yet know the initializer. This issue doesn't arise in C because
- // Rust initializers, unlike C initializers, can be indirectly
- // recursive. To ensure that compute_reloc_for_constant computes
- // the right value if some other initializer refers to this one, we
- // mark this symbol as weak here. We undo that below in
- // immutable_struct_set_init before calling mark_decl_one_only.
- DECL_WEAK (decl) = 1;
- }
- if (is_constant)
- {
- TREE_READONLY (decl) = 1;
- TREE_CONSTANT (decl) = 1;
- }
- if (alignment != 0)
- {
- SET_DECL_ALIGN (decl, alignment * BITS_PER_UNIT);
- DECL_USER_ALIGN (decl) = 1;
- }
- if (!asm_name.empty ())
- SET_DECL_ASSEMBLER_NAME (decl, get_identifier_from_string (asm_name));
-
- rust_preserve_from_gc (decl);
- return new Bvariable (decl);
-}
-
-// Set the initalizer for a variable created by implicit_variable.
-// This is where we finish compiling the variable.
-
-void
-Gcc_backend::implicit_variable_set_init (Bvariable *var, const std::string &,
- tree, bool, bool, bool is_common,
- tree init_tree)
-{
- tree decl = var->get_decl ();
- if (decl == error_mark_node || init_tree == error_mark_node)
- return;
-
- DECL_INITIAL (decl) = init_tree;
-
- // Now that DECL_INITIAL is set, we can't call make_decl_one_only.
- // See the comment where DECL_WEAK is set in implicit_variable.
- if (is_common)
- {
- DECL_WEAK (decl) = 0;
- make_decl_one_only (decl, DECL_ASSEMBLER_NAME (decl));
- }
-
- resolve_unique_section (decl, 2, 1);
-
- rest_of_decl_compilation (decl, 1, 0);
-}
-
-// Return a reference to an implicit variable defined in another package.
-
-Bvariable *
-Gcc_backend::implicit_variable_reference (const std::string &name,
- const std::string &asm_name,
- tree type_tree)
-{
- if (type_tree == error_mark_node)
- return this->error_variable ();
-
- tree decl = build_decl (BUILTINS_LOCATION, VAR_DECL,
- get_identifier_from_string (name), type_tree);
- DECL_EXTERNAL (decl) = 1;
- TREE_PUBLIC (decl) = 1;
- TREE_STATIC (decl) = 0;
- DECL_ARTIFICIAL (decl) = 1;
- if (!asm_name.empty ())
- SET_DECL_ASSEMBLER_NAME (decl, get_identifier_from_string (asm_name));
- rust_preserve_from_gc (decl);
- return new Bvariable (decl);
-}
-
-// Create a named immutable initialized data structure.
-
-Bvariable *
-Gcc_backend::immutable_struct (const std::string &name,
- const std::string &asm_name, bool is_hidden,
- bool is_common, tree type_tree,
- Location location)
-{
- if (type_tree == error_mark_node)
- return this->error_variable ();
- gcc_assert (TREE_CODE (type_tree) == RECORD_TYPE);
- tree decl = build_decl (location.gcc_location (), VAR_DECL,
- get_identifier_from_string (name),
- build_qualified_type (type_tree, TYPE_QUAL_CONST));
- TREE_STATIC (decl) = 1;
- TREE_USED (decl) = 1;
- TREE_READONLY (decl) = 1;
- TREE_CONSTANT (decl) = 1;
- DECL_ARTIFICIAL (decl) = 1;
- if (!is_hidden)
- TREE_PUBLIC (decl) = 1;
- if (!asm_name.empty ())
- SET_DECL_ASSEMBLER_NAME (decl, get_identifier_from_string (asm_name));
-
- // When the initializer for one immutable_struct refers to another,
- // it needs to know the visibility of the referenced struct so that
- // compute_reloc_for_constant will return the right value. On many
- // systems calling make_decl_one_only will mark the decl as weak,
- // which will change the return value of compute_reloc_for_constant.
- // We can't reliably call make_decl_one_only yet, because we don't
- // yet know the initializer. This issue doesn't arise in C because
- // Rust initializers, unlike C initializers, can be indirectly
- // recursive. To ensure that compute_reloc_for_constant computes
- // the right value if some other initializer refers to this one, we
- // mark this symbol as weak here. We undo that below in
- // immutable_struct_set_init before calling mark_decl_one_only.
- if (is_common)
- DECL_WEAK (decl) = 1;
-
- // We don't call rest_of_decl_compilation until we have the
- // initializer.
-
- rust_preserve_from_gc (decl);
- return new Bvariable (decl);
-}
-
-// Set the initializer for a variable created by immutable_struct.
-// This is where we finish compiling the variable.
-
-void
-Gcc_backend::immutable_struct_set_init (Bvariable *var, const std::string &,
- bool, bool is_common, tree, Location,
- tree init_tree)
-{
- tree decl = var->get_decl ();
- if (decl == error_mark_node || init_tree == error_mark_node)
- return;
-
- DECL_INITIAL (decl) = init_tree;
-
- // Now that DECL_INITIAL is set, we can't call make_decl_one_only.
- // See the comment where DECL_WEAK is set in immutable_struct.
- if (is_common)
- {
- DECL_WEAK (decl) = 0;
- make_decl_one_only (decl, DECL_ASSEMBLER_NAME (decl));
- }
-
- // These variables are often unneeded in the final program, so put
- // them in their own section so that linker GC can discard them.
- resolve_unique_section (decl, compute_reloc_for_constant (init_tree), 1);
-
- rest_of_decl_compilation (decl, 1, 0);
-}
-
-// Return a reference to an immutable initialized data structure
-// defined in another package.
-
-Bvariable *
-Gcc_backend::immutable_struct_reference (const std::string &name,
- const std::string &asm_name,
- tree type_tree, Location location)
-{
- if (type_tree == error_mark_node)
- return this->error_variable ();
- gcc_assert (TREE_CODE (type_tree) == RECORD_TYPE);
- tree decl = build_decl (location.gcc_location (), VAR_DECL,
- get_identifier_from_string (name),
- build_qualified_type (type_tree, TYPE_QUAL_CONST));
- TREE_READONLY (decl) = 1;
- TREE_CONSTANT (decl) = 1;
- DECL_ARTIFICIAL (decl) = 1;
- TREE_PUBLIC (decl) = 1;
- DECL_EXTERNAL (decl) = 1;
- if (!asm_name.empty ())
- SET_DECL_ASSEMBLER_NAME (decl, get_identifier_from_string (asm_name));
- rust_preserve_from_gc (decl);
- return new Bvariable (decl);
-}
-
// Make a label.
tree