public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Arthur Cohen <cohenarthur@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r14-7694] gccrs: Stop autoderef of raw pointer types Date: Tue, 16 Jan 2024 17:54:25 +0000 (GMT) [thread overview] Message-ID: <20240116175425.281743858415@sourceware.org> (raw) https://gcc.gnu.org/g:b3b3de1082eeeee73fec1d27ad732b8369ee1d27 commit r14-7694-gb3b3de1082eeeee73fec1d27ad732b8369ee1d27 Author: Philip Herron <herron.philip@googlemail.com> Date: Sun Jun 25 21:36:32 2023 +0100 gccrs: Stop autoderef of raw pointer types It is unsafe to deref raw pointers during autoderef this adds a check to stop autoderef early when we are about to try and deref pointers. Fixes #2015 gcc/rust/ChangeLog: * typecheck/rust-autoderef.cc (AutoderefCycle::cycle): add check for pointers Signed-off-by: Philip Herron <herron.philip@googlemail.com> Diff: --- gcc/rust/typecheck/rust-autoderef.cc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/gcc/rust/typecheck/rust-autoderef.cc b/gcc/rust/typecheck/rust-autoderef.cc index 9450cfaa068..c70420a7c30 100644 --- a/gcc/rust/typecheck/rust-autoderef.cc +++ b/gcc/rust/typecheck/rust-autoderef.cc @@ -336,7 +336,6 @@ AutoderefCycle::cycle (TyTy::BaseType *receiver) return false; // try unsize - Adjustment unsize = Adjuster::try_unsize_type (r); if (!unsize.is_error ()) { @@ -351,6 +350,13 @@ AutoderefCycle::cycle (TyTy::BaseType *receiver) adjustments.pop_back (); } + bool is_ptr = receiver->get_kind () == TyTy::TypeKind::POINTER; + if (is_ptr) + { + // deref of raw pointers is unsafe + return false; + } + Adjustment deref = Adjuster::try_deref_type (r, Analysis::RustLangItem::ItemType::DEREF); if (!deref.is_error ())
reply other threads:[~2024-01-16 17:54 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=20240116175425.281743858415@sourceware.org \ --to=cohenarthur@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: linkBe 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).