public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-7694] gccrs: Stop autoderef of raw pointer types
@ 2024-01-16 17:54 Arthur Cohen
  0 siblings, 0 replies; only message in thread
From: Arthur Cohen @ 2024-01-16 17:54 UTC (permalink / raw)
  To: gcc-cvs

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

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

only message in thread, other threads:[~2024-01-16 17:54 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-16 17:54 [gcc r14-7694] gccrs: Stop autoderef of raw pointer types Arthur Cohen

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