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] Fix ICE with duplicate hirid on autoderef coercion site mappings
Date: Sat,  6 Aug 2022 12:09:45 +0000 (GMT)	[thread overview]
Message-ID: <20220806120945.943C63858285@sourceware.org> (raw)

https://gcc.gnu.org/g:405d9f1d135771015199546cd1c224ba589ab48d

commit 405d9f1d135771015199546cd1c224ba589ab48d
Author: Philip Herron <philip.herron@embecosm.com>
Date:   Wed Aug 3 11:58:06 2022 +0100

    Fix ICE with duplicate hirid on autoderef coercion site mappings
    
    Imagine the call expression:
    
      Foo(a+b)
    
    But the a+b is an operator overload of the assignment operation. We store
    the autoderef coercions on the HIR id of the plus_expression here which is
    going to conflict with the id used to store the autoderef coercions the
    argument a+b. So this patch changes that all autoderef coercions store the
    autoderef for the implicit method call on the hirid of the lvalue hirid
    which in this case is 'a'. This means we won't conflict and cause an ICE
    in this case.

Diff:
---
 gcc/rust/backend/rust-compile-expr.cc          |  2 +-
 gcc/rust/hir/tree/rust-hir-expr.h              | 26 +++++++++++++++++++++-----
 gcc/rust/typecheck/rust-hir-type-check-expr.cc |  2 +-
 3 files changed, 23 insertions(+), 7 deletions(-)

diff --git a/gcc/rust/backend/rust-compile-expr.cc b/gcc/rust/backend/rust-compile-expr.cc
index 92c224c68c9..35861c12d9c 100644
--- a/gcc/rust/backend/rust-compile-expr.cc
+++ b/gcc/rust/backend/rust-compile-expr.cc
@@ -1285,7 +1285,7 @@ CompileExpr::resolve_operator_overload (
   // lookup the autoderef mappings
   std::vector<Resolver::Adjustment> *adjustments = nullptr;
   ok = ctx->get_tyctx ()->lookup_autoderef_mappings (
-    expr.get_mappings ().get_hirid (), &adjustments);
+    expr.get_lvalue_mappings ().get_hirid (), &adjustments);
   rust_assert (ok);
 
   // apply adjustments for the fn call
diff --git a/gcc/rust/hir/tree/rust-hir-expr.h b/gcc/rust/hir/tree/rust-hir-expr.h
index d16ac92f6ca..7cb86a69b2c 100644
--- a/gcc/rust/hir/tree/rust-hir-expr.h
+++ b/gcc/rust/hir/tree/rust-hir-expr.h
@@ -4120,31 +4120,47 @@ class OperatorExprMeta
 {
 public:
   OperatorExprMeta (HIR::CompoundAssignmentExpr &expr)
-    : node_mappings (expr.get_mappings ()), locus (expr.get_locus ())
+    : node_mappings (expr.get_mappings ()),
+      lvalue_mappings (expr.get_expr ()->get_mappings ()),
+      locus (expr.get_locus ())
   {}
 
   OperatorExprMeta (HIR::ArithmeticOrLogicalExpr &expr)
-    : node_mappings (expr.get_mappings ()), locus (expr.get_locus ())
+    : node_mappings (expr.get_mappings ()),
+      lvalue_mappings (expr.get_expr ()->get_mappings ()),
+      locus (expr.get_locus ())
   {}
 
   OperatorExprMeta (HIR::NegationExpr &expr)
-    : node_mappings (expr.get_mappings ()), locus (expr.get_locus ())
+    : node_mappings (expr.get_mappings ()),
+      lvalue_mappings (expr.get_expr ()->get_mappings ()),
+      locus (expr.get_locus ())
   {}
 
   OperatorExprMeta (HIR::DereferenceExpr &expr)
-    : node_mappings (expr.get_mappings ()), locus (expr.get_locus ())
+    : node_mappings (expr.get_mappings ()),
+      lvalue_mappings (expr.get_expr ()->get_mappings ()),
+      locus (expr.get_locus ())
   {}
 
   OperatorExprMeta (HIR::ArrayIndexExpr &expr)
-    : node_mappings (expr.get_mappings ()), locus (expr.get_locus ())
+    : node_mappings (expr.get_mappings ()),
+      lvalue_mappings (expr.get_array_expr ()->get_mappings ()),
+      locus (expr.get_locus ())
   {}
 
   const Analysis::NodeMapping &get_mappings () const { return node_mappings; }
 
+  const Analysis::NodeMapping &get_lvalue_mappings () const
+  {
+    return lvalue_mappings;
+  }
+
   Location get_locus () const { return locus; }
 
 private:
   const Analysis::NodeMapping node_mappings;
+  const Analysis::NodeMapping lvalue_mappings;
   Location locus;
 };
 
diff --git a/gcc/rust/typecheck/rust-hir-type-check-expr.cc b/gcc/rust/typecheck/rust-hir-type-check-expr.cc
index d96a85cc342..80f351a8c45 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-expr.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-expr.cc
@@ -365,7 +365,7 @@ TypeCheckExpr::resolve_operator_overload (
     }
 
   // store the adjustments for code-generation to know what to do
-  context->insert_autoderef_mappings (expr.get_mappings ().get_hirid (),
+  context->insert_autoderef_mappings (expr.get_lvalue_mappings ().get_hirid (),
 				      std::move (candidate.adjustments));
 
   // now its just like a method-call-expr


                 reply	other threads:[~2022-08-06 12:09 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=20220806120945.943C63858285@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).