[PATCH] Remove split-stack from backend

2021-08-03 Thread Mark Wielaard
The backend was derived from the go backend which enables split stack
support by default. This inserts a __morestack call at the start of
each function. This is not needed for the rust backend. Remove the
split stack support code from the rust backend and spec.
---
 gcc/rust/rust-backend.h | 12 ---
 gcc/rust/rust-gcc.cc|  5 -
 gcc/rust/rustspec.cc| 47 -
 3 files changed, 4 insertions(+), 60 deletions(-)

diff --git a/gcc/rust/rust-backend.h b/gcc/rust/rust-backend.h
index 4635796e953..1af76cfcc10 100644
--- a/gcc/rust/rust-backend.h
+++ b/gcc/rust/rust-backend.h
@@ -790,27 +790,23 @@ public:
   // recover and must be visible for correct panic recovery.
   static const unsigned int function_is_inlinable = 1 << 2;
 
-  // Set if the function may not split the stack.  This is set for the
-  // implementation of recover itself, among other things.
-  static const unsigned int function_no_split_stack = 1 << 3;
-
   // Set if the function does not return.  This is set for the
   // implementation of panic.
-  static const unsigned int function_does_not_return = 1 << 4;
+  static const unsigned int function_does_not_return = 1 << 3;
 
   // Set if the function should be put in a unique section if
   // possible.  This is used for field tracking.
-  static const unsigned int function_in_unique_section = 1 << 5;
+  static const unsigned int function_in_unique_section = 1 << 4;
 
   // Set if the function should be available for inlining in the
   // backend, but should not be emitted as a standalone function.  Any
   // call to the function that is not inlined should be treated as a
   // call to a function defined in a different compilation unit.  This
   // is like a C99 function marked inline but not extern.
-  static const unsigned int function_only_inline = 1 << 6;
+  static const unsigned int function_only_inline = 1 << 5;
 
   // const function
-  static const unsigned int function_read_only = 1 << 7;
+  static const unsigned int function_read_only = 1 << 6;
 
   // Declare or define a function of FNTYPE.
   // NAME is the Go name of the function.  ASM_NAME, if not the empty
diff --git a/gcc/rust/rust-gcc.cc b/gcc/rust/rust-gcc.cc
index 3e47a7cba7a..5c37cea20da 100644
--- a/gcc/rust/rust-gcc.cc
+++ b/gcc/rust/rust-gcc.cc
@@ -3382,11 +3382,6 @@ Gcc_backend::function (Btype *fntype, const std::string 
&name,
 }
   if ((flags & function_is_inlinable) == 0)
 DECL_UNINLINABLE (decl) = 1;
-  if ((flags & function_no_split_stack) != 0)
-{
-  tree attr = get_identifier ("no_split_stack");
-  DECL_ATTRIBUTES (decl) = tree_cons (attr, NULL_TREE, NULL_TREE);
-}
   if ((flags & function_does_not_return) != 0)
 TREE_THIS_VOLATILE (decl) = 1;
   if ((flags & function_in_unique_section) != 0)
diff --git a/gcc/rust/rustspec.cc b/gcc/rust/rustspec.cc
index 28c2d9a38fe..12ec874d222 100644
--- a/gcc/rust/rustspec.cc
+++ b/gcc/rust/rustspec.cc
@@ -104,9 +104,6 @@ lang_specific_driver (struct cl_decoded_option 
**in_decoded_options,
   /* The total number of arguments with the new stuff.  */
   int num_args = 1;
 
-  /* Supports split stack */
-  int supports_split_stack = 0;
-
   /* Whether the -o option was used.  */
   bool saw_opt_o = false;
 
@@ -118,11 +115,6 @@ lang_specific_driver (struct cl_decoded_option 
**in_decoded_options,
   /* Whether the -S option was used.  */
   bool saw_opt_S = false;
 
-#ifdef TARGET_CAN_SPLIT_STACK_64BIT
-  /* Whether the -m64 option is in force. */
-  bool is_m64 = TARGET_CAN_SPLIT_STACK_64BIT;
-#endif
-
   /* The first input file with an extension of .go.  */
   const char *first_go_file = NULL;
 
@@ -159,16 +151,6 @@ lang_specific_driver (struct cl_decoded_option 
**in_decoded_options,
library = (library == 0) ? 1 : library;
  break;
 
-#ifdef TARGET_CAN_SPLIT_STACK_64BIT
-   case OPT_m32:
- is_m64 = false;
- break;
-
-   case OPT_m64:
- is_m64 = true;
- break;
-#endif
-
case OPT_pg:
case OPT_p:
  saw_profile_flag = true;
@@ -253,23 +235,6 @@ lang_specific_driver (struct cl_decoded_option 
**in_decoded_options,
   /* Copy the 0th argument, i.e., the name of the program itself.  */
   new_decoded_options[j++] = decoded_options[i++];
 
-#ifdef TARGET_CAN_SPLIT_STACK
-  supports_split_stack = 1;
-#endif
-
-#ifdef TARGET_CAN_SPLIT_STACK_64BIT
-  if (is_m64)
-supports_split_stack = 1;
-#endif
-
-  /* If we are linking, pass -fsplit-stack if it is supported.  */
-  if ((library >= 0) && supports_split_stack)
-{
-  generate_option (OPT_fsplit_stack, NULL, 1, CL_DRIVER,
-  &new_decoded_options[j]);
-  j++;
-}
-
   /* NOTE: We start at 1 now, not 0.  */
   while (i < argc)
 {
@@ -402,18 +367,6 @@ lang_specific_driver (struct cl_decoded_option 
**in_decoded_options,
 generate_option (OPT_shared_libgcc, NULL, 1, CL_DRIVER,
 &new_decoded_options[j++]);
 
-  /* lib

[PATCH] Always check the result of expect_token while parsing

2021-08-03 Thread Mark Wielaard
When expect_token fails it produces an error and return a
nullptr. Make sure to always check the result of expect_token so we
don't use a nullptr token and crash.

Resolves: https://github.com/Rust-GCC/gccrs/issues/603
---
 gcc/rust/parse/rust-parse-impl.h | 27 +++
 1 file changed, 27 insertions(+)

diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h
index 9eb212b4e72..acc9d06acd7 100644
--- a/gcc/rust/parse/rust-parse-impl.h
+++ b/gcc/rust/parse/rust-parse-impl.h
@@ -1898,6 +1898,9 @@ Parser::parse_macro_match_fragment ()
 
   // get MacroFragSpec for macro
   const_TokenPtr t = expect_token (IDENTIFIER);
+  if (t == nullptr)
+return nullptr;
+
   AST::MacroFragSpec frag = AST::get_frag_spec_from_str (t->get_str ());
   if (frag == AST::INVALID)
 {
@@ -4325,6 +4328,9 @@ Parser::parse_enum (AST::Visibility 
vis,
 
   // parse enum name
   const_TokenPtr enum_name_tok = expect_token (IDENTIFIER);
+  if (enum_name_tok == nullptr)
+return nullptr;
+
   Identifier enum_name = enum_name_tok->get_str ();
 
   // parse generic params (of enum container, not enum variants) if they exist
@@ -4650,6 +4656,9 @@ Parser::parse_static_item 
(AST::Visibility vis,
 }
 
   const_TokenPtr ident_tok = expect_token (IDENTIFIER);
+  if (ident_tok == nullptr)
+return nullptr;
+
   Identifier ident = ident_tok->get_str ();
 
   if (!skip_token (COLON))
@@ -4700,6 +4709,9 @@ Parser::parse_trait (AST::Visibility 
vis,
 
   // parse trait name
   const_TokenPtr ident_tok = expect_token (IDENTIFIER);
+  if (ident_tok == nullptr)
+return nullptr;
+
   Identifier ident = ident_tok->get_str ();
 
   // parse generic parameters (if they exist)
@@ -4805,6 +4817,9 @@ Parser::parse_trait_item ()
 
// parse function or method name
const_TokenPtr ident_tok = expect_token (IDENTIFIER);
+   if (ident_tok == nullptr)
+ return nullptr;
+
Identifier ident = ident_tok->get_str ();
 
// parse generic params
@@ -4937,6 +4952,9 @@ Parser::parse_trait_type 
(AST::AttrVec outer_attrs)
   skip_token (TYPE);
 
   const_TokenPtr ident_tok = expect_token (IDENTIFIER);
+  if (ident_tok == nullptr)
+return nullptr;
+
   Identifier ident = ident_tok->get_str ();
 
   std::vector> bounds;
@@ -4973,6 +4991,9 @@ Parser::parse_trait_const 
(AST::AttrVec outer_attrs)
 
   // parse constant item name
   const_TokenPtr ident_tok = expect_token (IDENTIFIER);
+  if (ident_tok == nullptr)
+return nullptr;
+
   Identifier ident = ident_tok->get_str ();
 
   if (!skip_token (COLON))
@@ -5338,6 +5359,9 @@ 
Parser::parse_inherent_impl_function_or_method (
 
   // parse function or method name
   const_TokenPtr ident_tok = expect_token (IDENTIFIER);
+  if (ident_tok == nullptr)
+return nullptr;
+
   Identifier ident = ident_tok->get_str ();
 
   // parse generic params
@@ -14210,6 +14234,9 @@ Parser::parse_field_access_expr (
   /* get field name identifier (assume that this is a field access expr and not
* await, for instance) */
   const_TokenPtr ident_tok = expect_token (IDENTIFIER);
+  if (ident_tok == nullptr)
+return nullptr;
+
   Identifier ident = ident_tok->get_str ();
 
   Location locus = struct_expr->get_locus_slow ();
-- 
2.32.0

-- 
Gcc-rust mailing list
Gcc-rust@gcc.gnu.org
https://gcc.gnu.org/mailman/listinfo/gcc-rust