﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc	difficulty
1317	fibc hangs when compiled with -O3 or -O4	Mario Domenech Goulart		"The program below hangs eating CPU when compiled with -O3 or -O4:

{{{
(define (addc x y k)
  (if (zero? y)
    (k x)
    (addc (add1 x) (sub1 y) k)))

(define (fibc x c)
  (if (zero? x)
    (c 0)
    (if (zero? (sub1 x))
      (c 1)
      (addc (call-with-current-continuation (lambda (c) (fibc (sub1 x) c)))
            (call-with-current-continuation (lambda (c) (fibc (sub1 (sub1 x)) c)))
            c))))

(let ((x (time (fibc 30 (lambda (n) n)))))
  (if (not (equal? x 832040))
      (error ""wrong result"" x) ) )
}}}

{{{
$ csc fibc.scm 
$ ./fibc 
0.412s CPU time, 12/4237 GCs (major/minor)
}}}

{{{
$ csc -O3 fibc.scm 
$ ./fibc 
<hangs>
}}}

Also hangs when compiled with -O4.  It works as expected (i.e., doesn't hang) when compiled with -O5.

I could reproduce this behavior with 4.11.0 and master (as of 724f6866b). I could **not** reproduce the problem with 4.10.0, so the bug has been introduced at some point between 4.10.0 and 4.11.0. The issue doesn't seem to be related to the C compiler.  I could reproduce it with GCC 4.9.2, GCC 6.1.1 and clang 3.6.2.

This issue was caught while trying csc options for [https://github.com/mario-goulart/chicken-benchmarks chicken-benchmarks] (fibc is one of the benchmark programs)."	defect	closed	major	4.12.0	compiler	4.11.0	fixed	fibc, hang		hard
