From 7d7bc2ce3898294d67761ab176c2c229089fc13b Mon Sep 17 00:00:00 2001 From: Philip Herron Date: Mon, 14 Mar 2022 12:53:10 +0000 Subject: Fix memory corruption in generation of builtin functions When we compile normal language functions we maintain a stack of the current function declaration and associated return addresses. This is used while building up the GCC tree graph. When we generate builtin intrinsic functions such as offset or size_of were missing their associated push_fn but still performed a pop_fn on completion this resulted in a corrupt stack which valgrind shown as bad read/writes. This patch removes the pop_fn calls since no fncontext stack is required here for these intrinsics. Fixes #1024 --- gcc/rust/backend/rust-compile-intrinsic.cc | 4 ---- 1 file changed, 4 deletions(-) (limited to 'gcc/rust/backend') diff --git a/gcc/rust/backend/rust-compile-intrinsic.cc b/gcc/rust/backend/rust-compile-intrinsic.cc index 3665f5d..5fde694 100644 --- a/gcc/rust/backend/rust-compile-intrinsic.cc +++ b/gcc/rust/backend/rust-compile-intrinsic.cc @@ -304,8 +304,6 @@ offset_intrinsic_handler (Context *ctx, TyTy::BaseType *fntype_tyty) gcc_assert (TREE_CODE (bind_tree) == BIND_EXPR); DECL_SAVED_TREE (fndecl) = bind_tree; - - ctx->pop_fn (); ctx->push_function (fndecl); return fndecl; @@ -393,8 +391,6 @@ sizeof_intrinsic_handler (Context *ctx, TyTy::BaseType *fntype_tyty) gcc_assert (TREE_CODE (bind_tree) == BIND_EXPR); DECL_SAVED_TREE (fndecl) = bind_tree; - - ctx->pop_fn (); ctx->push_function (fndecl); return fndecl; -- cgit v1.1