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 undefined behaviour using .get on unique_ptr
Date: Fri, 15 Jul 2022 11:37:35 +0000 (GMT)	[thread overview]
Message-ID: <20220715113735.B6ED93857000@sourceware.org> (raw)

https://gcc.gnu.org/g:81c4b6989f044a45455717b752cafb96f04b768e

commit 81c4b6989f044a45455717b752cafb96f04b768e
Author: Philip Herron <philip.herron@embecosm.com>
Date:   Fri Jul 8 14:54:37 2022 +0100

    Fix undefined behaviour using .get on unique_ptr
    
    As the move semantics for AST and HIR crates are unsafe on older compilers
    we are working around this by storing the pointer into the mappings class
    this was using the get method to store the pointer. The issue for loading
    extern crates the unique_ptr goes out of scope and this the deletion code
    resulting in undefined behaviour. This changes it to call release to take
    full ownership of the pointer as we expect.

Diff:
---
 gcc/rust/util/rust-hir-map.cc | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/gcc/rust/util/rust-hir-map.cc b/gcc/rust/util/rust-hir-map.cc
index 353b7cb16ed..360dabf912f 100644
--- a/gcc/rust/util/rust-hir-map.cc
+++ b/gcc/rust/util/rust-hir-map.cc
@@ -199,7 +199,7 @@ Mappings::insert_ast_crate (std::unique_ptr<AST::Crate> &&crate,
   rust_assert (it == ast_crate_mappings.end ());
 
   // store it
-  ast_crate_mappings.insert ({crate_num, crate.get ()});
+  ast_crate_mappings.insert ({crate_num, crate.release ()});
 
   // return the reference to it
   it = ast_crate_mappings.find (crate_num);
@@ -236,7 +236,7 @@ Mappings::insert_hir_crate (std::unique_ptr<HIR::Crate> &&crate)
 
   insert_node_to_hir (crate->get_mappings ().get_nodeid (),
 		      crate->get_mappings ().get_hirid ());
-  hir_crate_mappings.insert ({crateNum, crate.get ()});
+  hir_crate_mappings.insert ({crateNum, crate.release ()});
 
   it = hir_crate_mappings.find (crateNum);
   rust_assert (it != hir_crate_mappings.end ());


                 reply	other threads:[~2022-07-15 11:37 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=20220715113735.B6ED93857000@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).