tech-pkg archive

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

Re: databases/sqlite on powerpc



David Holland <dholland-pkgtech%netbsd.org@localhost> writes:

> 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;

Thanks for explaining that.  This patch certainly can just go in immediately.

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

That's an interesting concept, and probably deserves a longer discussion
with its own thread.   (I see it as a slippery slope that ends with not
optimizing any file in any program in which a UB bug has previously been
found, which is pretty much any program.)

I'd rather us not head down this path in the waning days of the freeze
period.

Attachment: signature.asc
Description: PGP signature



Home | Main Index | Thread Index | Old Index