[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Guile-commits] 01/10: Fix bug in which codegen accessed data beyond end
From: |
Andy Wingo |
Subject: |
[Guile-commits] 01/10: Fix bug in which codegen accessed data beyond end of stack |
Date: |
Sun, 18 Aug 2019 17:12:18 -0400 (EDT) |
wingo pushed a commit to branch master
in repository guile.
commit 4bb5834d754aac50ba3288b232ea49f22cf21d0e
Author: Andy Wingo <address@hidden>
Date: Sun Aug 18 22:09:38 2019 +0200
Fix bug in which codegen accessed data beyond end of stack
* module/language/cps/compile-bytecode.scm (compile-function): When
shuffling return values, we need to reset the frame after any "extra"
values are read and before any "extra" values may be set.
---
module/language/cps/compile-bytecode.scm | 28 ++++++++++++++++++++--------
1 file changed, 20 insertions(+), 8 deletions(-)
diff --git a/module/language/cps/compile-bytecode.scm
b/module/language/cps/compile-bytecode.scm
index 669be8c..ff59317 100644
--- a/module/language/cps/compile-bytecode.scm
+++ b/module/language/cps/compile-bytecode.scm
@@ -380,6 +380,24 @@
(#('throw/value+data param (val))
(emit-throw/value+data asm (from-sp (slot val)) param))))
+ (define (emit-parallel-moves-after-return-and-reset-frame label nlocals)
+ (let lp ((moves (lookup-parallel-moves label allocation))
+ (reset-frame? #f))
+ (cond
+ ((and (not reset-frame?)
+ (and-map (match-lambda
+ ((src . dst)
+ (and (< src nlocals) (< dst nlocals))))
+ moves))
+ (emit-reset-frame asm nlocals)
+ (lp moves #t))
+ (else
+ (match moves
+ (() #t)
+ (((src . dst) . moves)
+ (emit-fmov asm dst src)
+ (lp moves reset-frame?)))))))
+
(define (compile-prompt label k kh escape? tag)
(match (intmap-ref cps kh)
(($ $kreceive ($ $arity req () rest () #f) khandler-body)
@@ -397,10 +415,7 @@
(($ $kargs names (_ ... rest))
(maybe-slot rest))))
(emit-bind-rest asm (+ proc-slot nreq)))
- (for-each (match-lambda
- ((src . dst) (emit-fmov asm dst src)))
- (lookup-parallel-moves kh allocation))
- (emit-reset-frame asm frame-size)
+ (emit-parallel-moves-after-return-and-reset-frame kh frame-size)
(emit-j asm (forward-label khandler-body))))))
(define (compile-values label exp syms)
@@ -544,10 +559,7 @@
(emit-receive-values asm proc-slot (->bool rest-var) nreq))
(when (and rest-var (maybe-slot rest-var))
(emit-bind-rest asm (+ proc-slot nreq)))
- (for-each (match-lambda
- ((src . dst) (emit-fmov asm dst src)))
- (lookup-parallel-moves k allocation))
- (emit-reset-frame asm frame-size)))))
+ (emit-parallel-moves-after-return-and-reset-frame k frame-size)))))
(match exp
(($ $call proc args)
(do-call proc args
- [Guile-commits] branch master updated (b16ad94 -> 2751096), Andy Wingo, 2019/08/18
- [Guile-commits] 01/10: Fix bug in which codegen accessed data beyond end of stack,
Andy Wingo <=
- [Guile-commits] 03/10: Simplify the define-primitive-expander macro, Andy Wingo, 2019/08/18
- [Guile-commits] 09/10: Fix coverage test for top-level binding optimization, Andy Wingo, 2019/08/18
- [Guile-commits] 08/10: Skip tests that don't work under letrectification, Andy Wingo, 2019/08/18
- [Guile-commits] 10/10: Define missing shuffling assembler for string-set! et al, Andy Wingo, 2019/08/18
- [Guile-commits] 07/10: Enable letrectification, Andy Wingo, 2019/08/18
- [Guile-commits] 05/10: Add letrectify tree-il pass, Andy Wingo, 2019/08/18
- [Guile-commits] 06/10: Add notion of declarative modules, Andy Wingo, 2019/08/18
- [Guile-commits] 02/10: Add "mod" field to tree-il toplevel ref, set, define, Andy Wingo, 2019/08/18
- [Guile-commits] 04/10: Add primitive support for working with module variables, Andy Wingo, 2019/08/18