Re: Probably a bug in LuaJIT x86

  • From: Mike Pall <mikelj-1808@xxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Thu, 16 Aug 2018 09:54:04 +0200

Egor Skriptunoff wrote:

   local dwords = ffi.typeof("uint32_t[?]")
   local ror = bit.ror

Bit operations have signed results.

         arr[i] = arr[i-2] + ror(arr[i-1], 7)

The result of the addition is a signed double. The conversion to
an unsigned FFI type (implicitly via the assignment) is undefined,
if the result is negative.

A small "bonus" (unrelated):

Compilation warning is displayed when building latest LuaJIT 2.1 under
VS2010:
   lib_base.c(302) : warning C4146: unary minus operator applied to
unsigned type, result still unsigned

The expression does what it's supposed to do. The warning
indicates that, too. I.e. it's harmless.

The workaround to silence that warning with an intermediate cast
to a signed type may cause warnings from other tools about
potentially undefined behavior (negation of 0x80000000). Which
doesn't happen in practice, but the tools can't infer that.

Since VC++ has a minority opinion wrt. that warning, I'll keep the
code that way.

--Mike

Other related posts: