Skip to content

Commit 7d7bc2c

Browse files
committed
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
1 parent 41f402f commit 7d7bc2c

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

gcc/rust/backend/rust-compile-intrinsic.cc

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -304,8 +304,6 @@ offset_intrinsic_handler (Context *ctx, TyTy::BaseType *fntype_tyty)
304304

305305
gcc_assert (TREE_CODE (bind_tree) == BIND_EXPR);
306306
DECL_SAVED_TREE (fndecl) = bind_tree;
307-
308-
ctx->pop_fn ();
309307
ctx->push_function (fndecl);
310308

311309
return fndecl;
@@ -393,8 +391,6 @@ sizeof_intrinsic_handler (Context *ctx, TyTy::BaseType *fntype_tyty)
393391

394392
gcc_assert (TREE_CODE (bind_tree) == BIND_EXPR);
395393
DECL_SAVED_TREE (fndecl) = bind_tree;
396-
397-
ctx->pop_fn ();
398394
ctx->push_function (fndecl);
399395

400396
return fndecl;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
extern "rust-intrinsic" {
2+
pub fn size_of<T>() -> usize;
3+
}
4+
5+
fn test() -> usize {
6+
unsafe { size_of::<i32>() }
7+
}
8+
9+
fn main() {
10+
let _a = test();
11+
}

0 commit comments

Comments
 (0)