aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorPhilip Herron <herron.philip@googlemail.com>2023-04-17 20:48:41 +0100
committerArthur Cohen <arthur.cohen@embecosm.com>2024-01-16 18:34:12 +0100
commite755e6e407be2ed3d6d3d93a215a9237c681026d (patch)
tree20d0f8db0bed6b8d43cfc8aa7d2aacdee976dec2 /gcc
parent315e267e8be68acd710c8868ca2ba7433d70239b (diff)
downloadgcc-e755e6e407be2ed3d6d3d93a215a9237c681026d.zip
gcc-e755e6e407be2ed3d6d3d93a215a9237c681026d.tar.gz
gcc-e755e6e407be2ed3d6d3d93a215a9237c681026d.tar.bz2
gccrs: Fix memory corruption at peek_context
When working in the resolve_operator_overload it was found that we got memory corruption as method resolution will use the query system and therefore resolve new methods and the current function context info will change and due to the fact the peek_context interface returns a reference to the element which was now safe from a vector which can change and all you need is the current function context at that moment in time. gcc/rust/ChangeLog: * typecheck/rust-autoderef.cc: don't take a reference * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): likewise * typecheck/rust-hir-type-check.h: remove reference * typecheck/rust-typecheck-context.cc (TypeCheckContext::pop_return_type): likewise Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Diffstat (limited to 'gcc')
-rw-r--r--gcc/rust/typecheck/rust-autoderef.cc2
-rw-r--r--gcc/rust/typecheck/rust-hir-type-check-expr.cc4
-rw-r--r--gcc/rust/typecheck/rust-hir-type-check.h2
-rw-r--r--gcc/rust/typecheck/rust-typecheck-context.cc2
4 files changed, 5 insertions, 5 deletions
diff --git a/gcc/rust/typecheck/rust-autoderef.cc b/gcc/rust/typecheck/rust-autoderef.cc
index d4a21ce..adaf575 100644
--- a/gcc/rust/typecheck/rust-autoderef.cc
+++ b/gcc/rust/typecheck/rust-autoderef.cc
@@ -164,7 +164,7 @@ resolve_operator_overload_fn (
// handle the case where we are within the impl block for this
// lang_item otherwise we end up with a recursive operator overload
// such as the i32 operator overload trait
- TypeCheckContextItem &fn_context = context->peek_context ();
+ TypeCheckContextItem fn_context = context->peek_context ();
if (fn_context.get_type () == TypeCheckContextItem::ItemType::IMPL_ITEM)
{
auto &impl_item = fn_context.get_impl_item ();
diff --git a/gcc/rust/typecheck/rust-hir-type-check-expr.cc b/gcc/rust/typecheck/rust-hir-type-check-expr.cc
index 6594068..ce215e3 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-expr.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-expr.cc
@@ -1457,7 +1457,7 @@ TypeCheckExpr::visit (HIR::MatchExpr &expr)
void
TypeCheckExpr::visit (HIR::ClosureExpr &expr)
{
- TypeCheckContextItem &current_context = context->peek_context ();
+ TypeCheckContextItem current_context = context->peek_context ();
TyTy::FnType *current_context_fndecl = current_context.get_context_type ();
HirId ref = expr.get_mappings ().get_hirid ();
@@ -1624,7 +1624,7 @@ TypeCheckExpr::resolve_operator_overload (
// handle the case where we are within the impl block for this lang_item
// otherwise we end up with a recursive operator overload such as the i32
// operator overload trait
- TypeCheckContextItem &fn_context = context->peek_context ();
+ TypeCheckContextItem fn_context = context->peek_context ();
if (fn_context.get_type () == TypeCheckContextItem::ItemType::IMPL_ITEM)
{
auto &impl_item = fn_context.get_impl_item ();
diff --git a/gcc/rust/typecheck/rust-hir-type-check.h b/gcc/rust/typecheck/rust-hir-type-check.h
index 427c56b..10aa3b3 100644
--- a/gcc/rust/typecheck/rust-hir-type-check.h
+++ b/gcc/rust/typecheck/rust-hir-type-check.h
@@ -90,7 +90,7 @@ public:
bool lookup_type_by_node_id (NodeId ref, HirId *id);
TyTy::BaseType *peek_return_type ();
- TypeCheckContextItem &peek_context ();
+ TypeCheckContextItem peek_context ();
void push_return_type (TypeCheckContextItem item,
TyTy::BaseType *return_type);
void pop_return_type ();
diff --git a/gcc/rust/typecheck/rust-typecheck-context.cc b/gcc/rust/typecheck/rust-typecheck-context.cc
index 7b2c96c..dcf06098 100644
--- a/gcc/rust/typecheck/rust-typecheck-context.cc
+++ b/gcc/rust/typecheck/rust-typecheck-context.cc
@@ -157,7 +157,7 @@ TypeCheckContext::pop_return_type ()
return_type_stack.pop_back ();
}
-TypeCheckContextItem &
+TypeCheckContextItem
TypeCheckContext::peek_context ()
{
rust_assert (!return_type_stack.empty ());