tech-pkg archive

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

Re: databases/sqlite on powerpc



On Thu, Jun 23, 2022 at 03:51:31PM +0200, Havard Eidnes wrote:
 > it seems I've come across a compiler bug on NetBSD/powerpc
 > -current;

Nope, it's UB in the source :-(

 > Building the tool "lemon" with debugging reveals inside
 > print_stack_union() around line 3071:
 > 
 >     hash = (hash & 0x7fffffff)%arraysize;
 >     while( types[hash] ){

Since hash is an int, that & is only defined if the sign bit is
already clear, so it's a nop, and by the prevailing logic used by
compilers these days, it can be dropped. Then you get a negative
result out of the mod.

Dunno why this doesn't break on every platform, but it's not exactly
uncommon for gcc's behavior to be machine-specific for no good reason.

Anyway, I'd patch it to

 -     hash = (hash & 0x7fffffff)%arraysize;
 +     hash = ((unsigned)hash & 0x7fffffff)%arraysize;

although building the tool without optimization might also be a good
idea as when there's one problem like this there's likely more.

-- 
David A. Holland
dholland%netbsd.org@localhost


Home | Main Index | Thread Index | Old Index