From: Marek Polacek <polacek@redhat.com>
To: GCC Patches <gcc-patches@gcc.gnu.org>
Subject: [PATCH] Tweak INTTYPE_MINIMUM to avoid warning
Date: Fri, 04 Sep 2015 11:03:00 -0000 [thread overview]
Message-ID: <20150904110156.GA2813@redhat.com> (raw)
While looking into something else I spotted this UB. I rewrote this
to use another UB, but I'd say left-shifting into the sign bit isn't
such an anathema as it was.
It's -Wshift-negative-value that warns on this. The reason why we haven't
seen the warning before is due to a bug I'm fixing in the other patch.
Bootstrapped/regtested on x86_64-linux, ok for trunk?
2015-09-03 Marek Polacek <polacek@redhat.com>
* system.h (INTTYPE_MINIMUM): Rewrite to avoid shift warning.
* system.h (INTTYPE_MINIMUM): Rewrite to avoid shift warning.
diff --git gcc/gcc/system.h gcc/gcc/system.h
index 9ca5b5f..78ad609 100644
--- gcc/gcc/system.h
+++ gcc/gcc/system.h
@@ -307,7 +307,7 @@ extern int errno;
/* The outer cast is needed to work around a bug in Cray C 5.0.3.0.
It is necessary at least when t == time_t. */
#define INTTYPE_MINIMUM(t) ((t) (INTTYPE_SIGNED (t) \
- ? ~ (t) 0 << (sizeof (t) * CHAR_BIT - 1) : (t) 0))
+ ? (t) 1 << (sizeof (t) * CHAR_BIT - 1) : (t) 0))
#define INTTYPE_MAXIMUM(t) ((t) (~ (t) 0 - INTTYPE_MINIMUM (t)))
/* Use that infrastructure to provide a few constants. */
diff --git gcc/libcpp/system.h gcc/libcpp/system.h
index b18d658..a2e8c26 100644
--- gcc/libcpp/system.h
+++ gcc/libcpp/system.h
@@ -230,7 +230,7 @@ extern int errno;
/* The outer cast is needed to work around a bug in Cray C 5.0.3.0.
It is necessary at least when t == time_t. */
#define INTTYPE_MINIMUM(t) ((t) (INTTYPE_SIGNED (t) \
- ? ~ (t) 0 << (sizeof(t) * CHAR_BIT - 1) : (t) 0))
+ ? (t) 1 << (sizeof (t) * CHAR_BIT - 1) : (t) 0))
#define INTTYPE_MAXIMUM(t) ((t) (~ (t) 0 - INTTYPE_MINIMUM (t)))
/* Use that infrastructure to provide a few constants. */
Marek
next reply other threads:[~2015-09-04 11:02 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-09-04 11:03 Marek Polacek [this message]
2015-09-04 21:45 ` Jeff Law
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=20150904110156.GA2813@redhat.com \
--to=polacek@redhat.com \
--cc=gcc-patches@gcc.gnu.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.
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 read-only IMAP folder(s) and NNTP newsgroup(s).