public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/rust/master] Fix undefined behaviour using .get on unique_ptr
@ 2022-07-15 11:37 Thomas Schwinge
  0 siblings, 0 replies; only message in thread
From: Thomas Schwinge @ 2022-07-15 11:37 UTC (permalink / raw)
  To: gcc-cvs

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 ());


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-07-15 11:37 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-15 11:37 [gcc/devel/rust/master] Fix undefined behaviour using .get on unique_ptr Thomas Schwinge

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).