diff options
author | Philip Herron <herron.philip@googlemail.com> | 2023-06-25 21:36:32 +0100 |
---|---|---|
committer | Philip Herron <philip.herron@embecosm.com> | 2023-06-25 21:18:56 +0000 |
commit | ac43e5899ccb83b4d11ce1ae5e441f7b3734b9b2 (patch) | |
tree | 001d280588296300c028967523901cfcbbd89892 | |
parent | 337ed0fd1ba488754335b824263cff297e26e3bd (diff) | |
download | gcc-ac43e5899ccb83b4d11ce1ae5e441f7b3734b9b2.zip gcc-ac43e5899ccb83b4d11ce1ae5e441f7b3734b9b2.tar.gz gcc-ac43e5899ccb83b4d11ce1ae5e441f7b3734b9b2.tar.bz2 |
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>
-rw-r--r-- | gcc/rust/typecheck/rust-autoderef.cc | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/gcc/rust/typecheck/rust-autoderef.cc b/gcc/rust/typecheck/rust-autoderef.cc index ae41663..df7986b 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 ()) |