zsh-workers
 help / color / mirror / code / Atom feed
* Undefined behaviour warnings with zsh.git and clang
@ 2015-07-14  8:48 İsmailDönmez
  2015-07-14  9:20 ` Peter Stephenson
  0 siblings, 1 reply; 2+ messages in thread
From: İsmailDönmez @ 2015-07-14  8:48 UTC (permalink / raw)
  To: zsh-workers

Hi,

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]
            v->isarr = flags | (isvarat ? SCANPM_ISVAR_AT : 0);
                                          ^~~~~~~~~~~~~~~
./zsh.h:1755:32: note: expanded from macro 'SCANPM_ISVAR_AT'
#define SCANPM_ISVAR_AT   ((-1)<<15)    /* "$foo[@]"-style substitution
                           ~~~~^
2 warnings generated.

make test is fine but the warning might be worth looking into.



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Undefined behaviour warnings with zsh.git and clang
  2015-07-14  8:48 Undefined behaviour warnings with zsh.git and clang İsmailDönmez
@ 2015-07-14  9:20 ` Peter Stephenson
  0 siblings, 0 replies; 2+ messages in thread
From: Peter Stephenson @ 2015-07-14  9:20 UTC (permalink / raw)
  To: zsh-workers

On Tue, 14 Jul 2015 08:48:17 +0000
İsmailDönmez <ismail@donmez.ws> 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.


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-07-14  9:20 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-14  8:48 Undefined behaviour warnings with zsh.git and clang İsmailDönmez
2015-07-14  9:20 ` Peter Stephenson

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).