diff options
author | Philip Herron <philip.herron@embecosm.com> | 2022-03-14 12:53:10 +0000 |
---|---|---|
committer | Philip Herron <philip.herron@embecosm.com> | 2022-03-14 12:57:01 +0000 |
commit | 7d7bc2ce3898294d67761ab176c2c229089fc13b (patch) | |
tree | 0feabb302e2ce7cc2652b235a1e498788df57f6e /gcc | |
parent | 41f402f0b19c7e4f19f8d4d65d15223d2752f302 (diff) | |
download | gcc-7d7bc2ce3898294d67761ab176c2c229089fc13b.zip gcc-7d7bc2ce3898294d67761ab176c2c229089fc13b.tar.gz gcc-7d7bc2ce3898294d67761ab176c2c229089fc13b.tar.bz2 |
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
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/rust/backend/rust-compile-intrinsic.cc | 4 | ||||
-rw-r--r-- | gcc/testsuite/rust/compile/torture/issue-1024.rs | 11 |
2 files changed, 11 insertions, 4 deletions
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; diff --git a/gcc/testsuite/rust/compile/torture/issue-1024.rs b/gcc/testsuite/rust/compile/torture/issue-1024.rs new file mode 100644 index 0000000..1095409 --- /dev/null +++ b/gcc/testsuite/rust/compile/torture/issue-1024.rs @@ -0,0 +1,11 @@ +extern "rust-intrinsic" { + pub fn size_of<T>() -> usize; +} + +fn test() -> usize { + unsafe { size_of::<i32>() } +} + +fn main() { + let _a = test(); +} |