lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Pierre Chapuis wrote:
> I have found that the behavior of this code changes depending
> on whether or not I add useless instructions in the middle of
> it when I use "-O3". For instance, if I add this somewhere in
> the middle of a loop:
>
>   unpack({})
>
> I get the correct output, but not if I comment it...

unpack() is not compiled, i.e. the trace is aborted there.

> I also get the correct output if I use "-O3 -O-fwd".

That could be anything, since forwarding is used extensively.

> This bug happens in a rather large program which I cannot publish
> and I have not been able to make a snippet that reproduces it.

Well, that kind of makes it hard to help you ...

> >Apparently the function that sets a bit to 1 is skipped sometimes:
> >
> >  local bit_set_1 = function(_bset,_byte,_bit)
> >    _bset[_byte] = bor(bset[_byte],bmask_1[_bit])
> >  end
> 
> To be even clearer: I have confirmed that function is *called* as
> expected
> (by adding debug traces to stderr inside it).
> It just doesn't do what it is expected to do, ie. set a bit to 1 in a
> FFI char* structure.

The function as written above certainly doesn't work. You mix
_bset and bset (without underscore).

Even if that's just a typo, there's a high likeliness you're
overflowing a buffer somewhere (e.g. due to mixup of 0-based vs.
1-based indexing). Try running under the memcheck tool of Valgrind
(see src/Makefile, -DLUAJIT_USE_SYSMALLOC -DLUAJIT_USE_VALGRIND,
CCDEBUG=-g). Also try to enable assertions.

--Mike