From: jjasmine <tanghocle...@gmail.com>

gcc/rust/ChangeLog:

        * expand/rust-macro-builtins-asm.cc (parse_reg_operand):
        Addresses warning, put warn unused in right place
        (parse_reg_operand_inout): Likewise.
        (parse_asm_arg): Likewise.
        * expand/rust-macro-builtins-asm.h (enum WARN_UNUSED_RESULT): Likewise.
        (enum InlineAsmParseError): Likewise.
        (validate): Likewise.
        (parse_asm_arg): Likewise.
        (parse_format_strings): Likewise.
        (parse_clobber_abi): Likewise.
        (parse_reg_operand): Likewise.
        (parse_reg_operand_in): Likewise.
        (parse_reg_operand_out): Likewise.
        (parse_reg_operand_lateout): Likewise.
        (parse_reg_operand_inout): Likewise.
        (parse_reg_operand_inlateout): Likewise.
        (parse_reg_operand_const): Likewise.
        (parse_reg_operand_sym): Likewise.
        (parse_reg_operand_unexpected): Likewise.
        (parse_asm): Likewise.
        (check_and_set): Likewise.
        (parse_options): Likewise.
        (parse_reg): Likewise.
        (parse_format_string): Likewise.

Signed-off-by: badumbatish <tanghocle...@gmail.com>
---
 gcc/rust/expand/rust-macro-builtins-asm.cc | 24 +++++++++++++---------
 gcc/rust/expand/rust-macro-builtins-asm.h  | 21 ++++++++++++++++++-
 2 files changed, 34 insertions(+), 11 deletions(-)

diff --git a/gcc/rust/expand/rust-macro-builtins-asm.cc 
b/gcc/rust/expand/rust-macro-builtins-asm.cc
index dbbe0fa7732..a9e339b92e7 100644
--- a/gcc/rust/expand/rust-macro-builtins-asm.cc
+++ b/gcc/rust/expand/rust-macro-builtins-asm.cc
@@ -16,6 +16,7 @@
 // along with GCC; see the file COPYING3.  If not see
 // <http://www.gnu.org/licenses/>.
 
+#include "expected.h"
 #include "rust-make-unique.h"
 #include "rust-macro-builtins-asm.h"
 #include "rust-ast-fragment.h"
@@ -208,15 +209,13 @@ parse_reg_operand (InlineAsmContext inline_asm_ctx)
       else
        {
          rust_error_at (token->get_locus (),
-                        "expected operand, clobber_abi, options, or "
-                        "additional template string");
+                        "expected operand, %s, options, or "
+                        "additional template string",
+                        "clobber_abi");
          return tl::unexpected<InlineAsmParseError> (COMMITTED);
        }
     }
 
-  tl::expected<InlineAsmContext, InlineAsmParseError> parsing_operand
-    = tl::expected<InlineAsmContext, InlineAsmParseError> (inline_asm_ctx);
-
   int slot = inline_asm_ctx.inline_asm.operands.size ();
 
   // Here is all parse_reg_operand functions we're using in a for loop
@@ -230,7 +229,8 @@ parse_reg_operand (InlineAsmContext inline_asm_ctx)
   // we propogate the result.
   for (auto &parse_func : parse_funcs)
     {
-      parsing_operand.emplace (inline_asm_ctx);
+      auto parsing_operand
+       = tl::expected<InlineAsmContext, InlineAsmParseError> (inline_asm_ctx);
       parsing_operand.map (parse_func);
 
       // Per rust's asm.rs's structure
@@ -281,7 +281,7 @@ parse_reg_operand (InlineAsmContext inline_asm_ctx)
        }
     }
 
-  return parsing_operand;
+  return inline_asm_ctx;
 }
 
 tl::expected<InlineAsmContext, InlineAsmParseError>
@@ -386,7 +386,10 @@ parse_reg_operand_inout (InlineAsmContext inline_asm_ctx)
        {
          if (!parser.skip_token (UNDERSCORE))
            {
-             parse_format_string (inline_asm_ctx);
+             auto result = parse_format_string (inline_asm_ctx);
+
+             if (!result.has_value ())
+               rust_unreachable ();
              // out_expr = parser.parse_expr();
            }
 
@@ -708,8 +711,9 @@ parse_asm_arg (InlineAsmContext inline_asm_ctx)
       // committed to anything So that the error bubbles up and we recover from
       // this error gracefully
       rust_error_at (token->get_locus (),
-                    "expected operand, clobber_abi, options, or additional "
-                    "template string");
+                    "expected operand, %s, options, or additional "
+                    "template string",
+                    "clobber_abi");
       return tl::unexpected<InlineAsmParseError> (COMMITTED);
     }
   return tl::expected<InlineAsmContext, InlineAsmParseError> (inline_asm_ctx);
diff --git a/gcc/rust/expand/rust-macro-builtins-asm.h 
b/gcc/rust/expand/rust-macro-builtins-asm.h
index d3ca9340156..69977701040 100644
--- a/gcc/rust/expand/rust-macro-builtins-asm.h
+++ b/gcc/rust/expand/rust-macro-builtins-asm.h
@@ -8,7 +8,7 @@
 #include "system.h"
 namespace Rust {
 
-enum WARN_UNUSED_RESULT InlineAsmParseError
+enum InlineAsmParseError
 {
   // Enum for InlineAsmParseError
 
@@ -77,50 +77,65 @@ public:
 };
 
 // Expected calls
+WARN_UNUSED_RESULT
 tl::expected<InlineAsmContext, InlineAsmParseError>
 validate (InlineAsmContext inline_asm_ctx);
 
+WARN_UNUSED_RESULT
 tl::expected<InlineAsmContext, InlineAsmParseError>
 parse_asm_arg (InlineAsmContext inline_asm_ctx);
 
+WARN_UNUSED_RESULT
 tl::expected<InlineAsmContext, InlineAsmParseError>
 parse_format_strings (InlineAsmContext inline_asm_ctx);
 
+WARN_UNUSED_RESULT
 tl::expected<InlineAsmContext, InlineAsmParseError>
 parse_clobber_abi (InlineAsmContext inline_asm_ctx);
 
 // From rustc
+WARN_UNUSED_RESULT
 tl::expected<InlineAsmContext, InlineAsmParseError>
 parse_reg_operand (InlineAsmContext inline_asm_ctx);
 
+WARN_UNUSED_RESULT
 tl::expected<InlineAsmContext, InlineAsmParseError>
 parse_reg_operand_in (InlineAsmContext inline_asm_ctx);
 
+WARN_UNUSED_RESULT
 tl::expected<InlineAsmContext, InlineAsmParseError>
 parse_reg_operand_out (InlineAsmContext inline_asm_ctx);
 
+WARN_UNUSED_RESULT
 tl::expected<InlineAsmContext, InlineAsmParseError>
 parse_reg_operand_lateout (InlineAsmContext inline_asm_ctx);
 
+WARN_UNUSED_RESULT
 tl::expected<InlineAsmContext, InlineAsmParseError>
 parse_reg_operand_inout (InlineAsmContext inline_asm_ctx);
 
+WARN_UNUSED_RESULT
 tl::expected<InlineAsmContext, InlineAsmParseError>
 parse_reg_operand_inlateout (InlineAsmContext inline_asm_ctx);
 
+WARN_UNUSED_RESULT
 tl::expected<InlineAsmContext, InlineAsmParseError>
 parse_reg_operand_const (InlineAsmContext inline_asm_ctx);
 
+WARN_UNUSED_RESULT
 tl::expected<InlineAsmContext, InlineAsmParseError>
 parse_reg_operand_sym (InlineAsmContext inline_asm_ctx);
 
+WARN_UNUSED_RESULT
 tl::expected<InlineAsmContext, InlineAsmParseError>
 parse_reg_operand_unexpected (InlineAsmContext inline_asm_ctx);
 
+WARN_UNUSED_RESULT
 tl::optional<AST::Fragment>
 parse_asm (location_t invoc_locus, AST::MacroInvocData &invoc,
           AST::InvocKind semicolon, AST::AsmKind is_global_asm);
 
+WARN_UNUSED_RESULT
 bool
 check_identifier (Parser<MacroInvocLexer> &parser, std::string ident);
 
@@ -128,16 +143,20 @@ void
 check_and_set (InlineAsmContext &inline_asm_ctx, AST::InlineAsmOption option);
 
 // From rustc
+WARN_UNUSED_RESULT
 tl::expected<InlineAsmContext, InlineAsmParseError>
 parse_options (InlineAsmContext &inline_asm_ctx);
 
 // From rustc
+WARN_UNUSED_RESULT
 tl::optional<AST::InlineAsmRegOrRegClass>
 parse_reg (InlineAsmContext &inline_asm_ctx);
 
+WARN_UNUSED_RESULT
 tl::optional<std::string>
 parse_format_string (InlineAsmContext &inline_asm_ctx);
 
+WARN_UNUSED_RESULT
 tl::optional<std::string>
 parse_label (Parser<MacroInvocLexer> &parser, TokenId last_token_id,
             InlineAsmContext &inline_asm_ctx);
-- 
2.45.2

Reply via email to