Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Undefined behaviour warnings with zsh.git and clang



On Tue, 14 Jul 2015 08:48:17 +0000
İsmailDönmez <ismail@xxxxxxxxx> wrote:
> With git master I started to see:
> 
> clang -c -I. -I../Src -I../Src -I../Src/Zle -I.  -DHAVE_CONFIG_H -O2 -fPIE -
> fstack-protector -I/usr/include/ncurses6/ncursesw -I/usr/include/ncurses6  -
> o params.o params.c
> params.c:1721:18: warning: shifting a negative signed value is undefined [-
> Wshift-negative-value]
>             v->isarr |= SCANPM_ISVAR_AT;
>                         ^~~~~~~~~~~~~~~
> ./zsh.h:1755:32: note: expanded from macro 'SCANPM_ISVAR_AT'
> #define SCANPM_ISVAR_AT   ((-1)<<15)    /* "$foo[@]"-style substitution
>                            ~~~~^
> params.c:1933:36: warning: shifting a negative signed value is undefined [-
> Wshift-negative-value]

This hasn't changed, but wherever the warning's started coming from it's
valid.  I think the following uses the same bit patterns and final value
without any undefined behaviour, unless anyone can see otherwise.
Alaternatively (-1 & ~0xFFFF) might be neater.

pws

diff --git a/Src/zsh.h b/Src/zsh.h
index 69fef33..a99c900 100644
--- a/Src/zsh.h
+++ b/Src/zsh.h
@@ -1752,9 +1752,10 @@ struct tieddata {
 				  * necessarily want to match multiple
 				  * elements
 				  */
-#define SCANPM_ISVAR_AT   ((-1)<<15)	/* "$foo[@]"-style substitution
-					 * Only sign bit is significant
-					 */
+/* "$foo[@]"-style substitution
+ * Only sign bit is significant
+ */
+#define SCANPM_ISVAR_AT   ((int)(((unsigned int)-1)<<15))
 
 /*
  * Flags for doing matches inside parameter substitutions, i.e.



Messages sorted by: Reverse Date, Date, Thread, Author