This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Tweak INTTYPE_MINIMUM to avoid warning
- From: Marek Polacek <polacek at redhat dot com>
- To: GCC Patches <gcc-patches at gcc dot gnu dot org>
- Date: Fri, 4 Sep 2015 13:01:56 +0200
- Subject: [PATCH] Tweak INTTYPE_MINIMUM to avoid warning
- Authentication-results: sourceware.org; auth=none
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