* [PATCH] Tweak INTTYPE_MINIMUM to avoid warning
@ 2015-09-04 11:03 Marek Polacek
2015-09-04 21:45 ` Jeff Law
0 siblings, 1 reply; 2+ messages in thread
From: Marek Polacek @ 2015-09-04 11:03 UTC (permalink / raw)
To: GCC Patches
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
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] Tweak INTTYPE_MINIMUM to avoid warning
2015-09-04 11:03 [PATCH] Tweak INTTYPE_MINIMUM to avoid warning Marek Polacek
@ 2015-09-04 21:45 ` Jeff Law
0 siblings, 0 replies; 2+ messages in thread
From: Jeff Law @ 2015-09-04 21:45 UTC (permalink / raw)
To: Marek Polacek, GCC Patches
On 09/04/2015 05:01 AM, Marek Polacek wrote:
> 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.
OK.
jeff
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2015-09-04 20:47 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-09-04 11:03 [PATCH] Tweak INTTYPE_MINIMUM to avoid warning Marek Polacek
2015-09-04 21:45 ` Jeff Law
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).