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 :-(

Nice...

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

Let me propose another and perhaps cleaner way of solving the build
problem, simply making "hash" unsigned, and remove the "and out the
sign bit" which is now no longer required.  Diff attached; build still
succeeds on powerpc with this.

Regards,

- Havard
Index: distinfo
===================================================================
RCS file: /cvsroot/pkgsrc/databases/sqlite/distinfo,v
retrieving revision 1.27
diff -u -p -r1.27 distinfo
--- distinfo	26 Oct 2021 10:10:05 -0000	1.27
+++ distinfo	24 Jun 2022 08:47:34 -0000
@@ -6,3 +6,4 @@ Size (sqlite-2.8.17.tar.gz) = 969805 byt
 SHA1 (patch-Makefile.in) = a7e6d0c15b6bd4c8c0f3a7123e82a145b3848703
 SHA1 (patch-aa) = 4df2eff8c92b3e2bff86c710ef1a803d54201559
 SHA1 (patch-ab) = 00b7de05589fb62d511e26d0d864a8b5545967c8
+SHA1 (patch-tool_lemon.c) = e4fdfcf7fd2e332e60eb7a1b20d5bfc4476f0f30
--- /dev/null	2022-06-24 10:44:59.464422127 +0200
+++ patches/patch-tool_lemon.c	2022-06-24 10:41:50.549516964 +0200
@@ -0,0 +1,22 @@
+$NetBSD$
+
+--- tool/lemon.c.orig	2005-04-23 22:43:22.000000000 +0000
++++ tool/lemon.c
+@@ -3016,7 +3016,7 @@ int mhflag;                 /* True if g
+   int maxdtlength;          /* Maximum length of any ".datatype" field. */
+   char *stddt;              /* Standardized name for a datatype */
+   int i,j;                  /* Loop counters */
+-  int hash;                 /* For hashing the name of a type */
++  unsigned int hash;        /* For hashing the name of a type */
+   char *name;               /* Name of the parser */
+ 
+   /* Allocate and initialize types[] and allocate stddt[] */
+@@ -3068,7 +3068,7 @@ int mhflag;                 /* True if g
+     for(j=0; stddt[j]; j++){
+       hash = hash*53 + stddt[j];
+     }
+-    hash = (hash & 0x7fffffff)%arraysize;
++    hash = hash % arraysize;
+     while( types[hash] ){
+       if( strcmp(types[hash],stddt)==0 ){
+         sp->dtnum = hash + 1;


Home | Main Index | Thread Index | Old Index