diff mbox

Tweak INTTYPE_MINIMUM to avoid warning

Message ID 20150904110156.GA2813@redhat.com
State New
Headers show

Commit Message

Marek Polacek Sept. 4, 2015, 11:01 a.m. UTC
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.


	Marek

Comments

Jeff Law Sept. 4, 2015, 8:47 p.m. UTC | #1
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
diff mbox

Patch

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.  */