From bc646d01c501f2566fd78057e23c283cfedc0eb0 Mon Sep 17 00:00:00 2001 From: Graydon Hoare Date: Mon, 13 Sep 2010 13:37:24 -0700 Subject: [PATCH] Fix leaking arg slots on tail calls. Closes #160. --- src/Makefile | 1 + src/boot/me/trans.ml | 2 ++ src/test/run-pass/tail-call-arg-leak.rs | 11 +++++++++++ 3 files changed, 14 insertions(+) create mode 100644 src/test/run-pass/tail-call-arg-leak.rs diff --git a/src/Makefile b/src/Makefile index 56fe9b98b38..8400e7a10f8 100644 --- a/src/Makefile +++ b/src/Makefile @@ -533,6 +533,7 @@ TEST_XFAILS_LLVM := $(TASK_XFAILS) \ str-concat.rs \ str-idx.rs \ tag.rs \ + tail-call-arg-leak.rs \ tail-cps.rs \ tail-direct.rs \ task-comm.rs \ diff --git a/src/boot/me/trans.ml b/src/boot/me/trans.ml index ad0d6445d70..dd1dd46da43 100644 --- a/src/boot/me/trans.ml +++ b/src/boot/me/trans.ml @@ -4219,6 +4219,8 @@ let trans_visitor (Printf.sprintf "copy args for tail call to %s" (logname ()))); copy_fn_args true true CLONE_none call; drop_slots_at_curr_stmt(); + iflog (fun _ -> annotate "drop args"); + iter_arg_slots cx (current_fn()) callee_drop_slot; abi.Abi.abi_emit_fn_tail_call (emitter()) (force_sz (current_fn_callsz())) caller_argsz callee_code callee_argsz; diff --git a/src/test/run-pass/tail-call-arg-leak.rs b/src/test/run-pass/tail-call-arg-leak.rs new file mode 100644 index 00000000000..d99ceaec03b --- /dev/null +++ b/src/test/run-pass/tail-call-arg-leak.rs @@ -0,0 +1,11 @@ +// use of tail calls causes arg slot leaks, issue #160. + +fn inner(str dummy, bool b) { + if (b) { + be inner(dummy, false); + } +} + +fn main() { + inner("hi", true); +}