public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Thomas Schwinge <tschwinge@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc/devel/rust/master] Ensure we don't return error_mark_node for loop expressions
Date: Wed,  8 Jun 2022 12:44:39 +0000 (GMT)	[thread overview]
Message-ID: <20220608124439.43C9F38936F7@sourceware.org> (raw)

https://gcc.gnu.org/g:0d8c298443615c1fd75c9af10ca26c7c36b69273

commit 0d8c298443615c1fd75c9af10ca26c7c36b69273
Author: Philip Herron <philip.herron@embecosm.com>
Date:   Fri May 6 12:30:47 2022 +0100

    Ensure we don't return error_mark_node for loop expressions
    
    Loop expressions can return a value even if its a unit-type so we must
    ensure we don't return an error_mark_node for the eventual coercion site
    for the unit-type case.
    
    Offending test-case was: rust/compile/torture/loop7.rs

Diff:
---
 gcc/rust/backend/rust-compile-expr.h | 32 ++++++++++++--------------------
 1 file changed, 12 insertions(+), 20 deletions(-)

diff --git a/gcc/rust/backend/rust-compile-expr.h b/gcc/rust/backend/rust-compile-expr.h
index bb81d4ed7bc..080686f9ce7 100644
--- a/gcc/rust/backend/rust-compile-expr.h
+++ b/gcc/rust/backend/rust-compile-expr.h
@@ -552,21 +552,16 @@ public:
       }
 
     fncontext fnctx = ctx->peek_fn ();
-    Bvariable *tmp = NULL;
-    bool needs_temp = !block_tyty->is_unit ();
-    if (needs_temp)
-      {
-	tree enclosing_scope = ctx->peek_enclosing_scope ();
-	tree block_type = TyTyResolveCompile::compile (ctx, block_tyty);
+    tree enclosing_scope = ctx->peek_enclosing_scope ();
+    tree block_type = TyTyResolveCompile::compile (ctx, block_tyty);
 
-	bool is_address_taken = false;
-	tree ret_var_stmt = NULL_TREE;
-	tmp = ctx->get_backend ()->temporary_variable (
-	  fnctx.fndecl, enclosing_scope, block_type, NULL, is_address_taken,
-	  expr.get_locus (), &ret_var_stmt);
-	ctx->add_statement (ret_var_stmt);
-	ctx->push_loop_context (tmp);
-      }
+    bool is_address_taken = false;
+    tree ret_var_stmt = NULL_TREE;
+    Bvariable *tmp = ctx->get_backend ()->temporary_variable (
+      fnctx.fndecl, enclosing_scope, block_type, NULL, is_address_taken,
+      expr.get_locus (), &ret_var_stmt);
+    ctx->add_statement (ret_var_stmt);
+    ctx->push_loop_context (tmp);
 
     if (expr.has_loop_label ())
       {
@@ -595,12 +590,9 @@ public:
       = ctx->get_backend ()->loop_expression (code_block, expr.get_locus ());
     ctx->add_statement (loop_expr);
 
-    if (tmp != NULL)
-      {
-	ctx->pop_loop_context ();
-	translated
-	  = ctx->get_backend ()->var_expression (tmp, expr.get_locus ());
-      }
+    ctx->pop_loop_context ();
+    translated = ctx->get_backend ()->var_expression (tmp, expr.get_locus ());
+
     ctx->pop_loop_begin_label ();
   }


                 reply	other threads:[~2022-06-08 12:44 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220608124439.43C9F38936F7@sourceware.org \
    --to=tschwinge@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).