zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.stephenson@samsung.com>
To: zsh-workers@zsh.org
Subject: Re: Undefined behaviour warnings with zsh.git and clang
Date: Tue, 14 Jul 2015 10:20:33 +0100	[thread overview]
Message-ID: <20150714102033.0f92c5de@pwslap01u.europe.root.pri> (raw)
In-Reply-To: <loom.20150714T104717-624@post.gmane.org>

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.


      reply	other threads:[~2015-07-14  9:20 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-14  8:48 İsmailDönmez
2015-07-14  9:20 ` Peter Stephenson [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150714102033.0f92c5de@pwslap01u.europe.root.pri \
    --to=p.stephenson@samsung.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).