luajit 2.0 jit bug with and/or expression?

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

luajit 2.0 jit bug with and/or expression?

Felix Wu
The following function ran fine with JIT off (-joff) for both LuaJIT
2.0 beta 8 and 9, but got erroneous results with JIT on. Is this a
known bug?

(1) with -joff

    > function fib(n) return (n < 2) and 1 or fib(n-1)+fib(n-2) end
    > = fib(10)
    89
    > =fib(20)
    10946

(2) without -joff

    > function fib(n) return (n < 2) and 1 or fib(n-1)+fib(n-2) end
    > = fib(10)
    79
    > = fib(20)
    stdin:1: attempt to perform arithmetic on a nil value

Reply | Threaded
Open this post in threaded view
|

Re: luajit 2.0 jit bug with and/or expression?

Francesco Abbate
2012/4/10 Felix Wu <[hidden email]>:
> The following function ran fine with JIT off (-joff) for both LuaJIT
> 2.0 beta 8 and 9, but got erroneous results with JIT on. Is this a
> known bug?

Hi,

don't know if this is a known bug or not but I was surprised that such
a simple example can produce an error of this kind.

I've made some tests and the bug disappear if you use a more
conventional if/then/else construct:

  if n < 2 then
    return 1
  else
    return fib(n-1) + fib(n-2)
  end

Francesco

Reply | Threaded
Open this post in threaded view
|

Re: luajit 2.0 jit bug with and/or expression?

Javier Guerra Giraldez
On Tue, Apr 10, 2012 at 3:53 PM, Francesco Abbate
<[hidden email]> wrote:
> don't know if this is a known bug or not but I was surprised that such
> a simple example can produce an error of this kind.

same here.

for the record, it seems to work ok with beta5 with either JIT off or
on (with and without -joff)

--
Javier

Reply | Threaded
Open this post in threaded view
|

Re: luajit 2.0 jit bug with and/or expression?

Mike Pall-38
In reply to this post by Felix Wu
Felix Wu wrote:

> The following function ran fine with JIT off (-joff) for both LuaJIT
> 2.0 beta 8 and 9, but got erroneous results with JIT on. Is this a
> known bug?
>
> (1) with -joff
>
>     > function fib(n) return (n < 2) and 1 or fib(n-1)+fib(n-2) end
>     > = fib(10)
>     89
>     > =fib(20)
>     10946
>
> (2) without -joff
>
>     > function fib(n) return (n < 2) and 1 or fib(n-1)+fib(n-2) end
>     > = fib(10)
>     79
>     > = fib(20)
>     stdin:1: attempt to perform arithmetic on a nil value

Thank you for the bug report and the test case! Fixed in git HEAD.

[That was a wrong data flow optimization hint in the bytecode.
That's why it's of rather basic nature, but only shows up under
very specific circumstances, when the code is JIT-compiled.]

--Mike

Reply | Threaded
Open this post in threaded view
|

Re: luajit 2.0 jit bug with and/or expression?

gkalas
This post has NOT been accepted by the mailing list yet.
I encountered this a few months ago, but I was not able to reproduce it, I thought I messed up something.
When can we expect a tag with this fix in?

Cheers,
Gergely