aboutsummaryrefslogtreecommitdiff
path: root/gcc/c-family
diff options
context:
space:
mode:
authorMarek Polacek <polacek@redhat.com>2015-08-12 17:25:23 +0000
committerMarek Polacek <mpolacek@gcc.gnu.org>2015-08-12 17:25:23 +0000
commitb893e375096038ac99521a97b7fa346b016bdb78 (patch)
tree61fb3ae13f36228936da84dc60d9e477d727f37e /gcc/c-family
parentbb2978b8fd41165054ffe3cfcfa5311fffaf13cd (diff)
downloadgcc-b893e375096038ac99521a97b7fa346b016bdb78.zip
gcc-b893e375096038ac99521a97b7fa346b016bdb78.tar.gz
gcc-b893e375096038ac99521a97b7fa346b016bdb78.tar.bz2
re PR c++/55095 (Wshift-overflow)
PR c++/55095 * c-common.c (maybe_warn_shift_overflow): Properly handle left-shifting 1 into the sign bit. * c-c++-common/Wshift-overflow-6.c: New test. * c-c++-common/Wshift-overflow-7.c: New test. * g++.dg/cpp1y/left-shift-2.C: New test. From-SVN: r226826
Diffstat (limited to 'gcc/c-family')
-rw-r--r--gcc/c-family/ChangeLog6
-rw-r--r--gcc/c-family/c-common.c7
2 files changed, 9 insertions, 4 deletions
diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog
index af1f098..c67c26c 100644
--- a/gcc/c-family/ChangeLog
+++ b/gcc/c-family/ChangeLog
@@ -1,3 +1,9 @@
+2015-08-12 Marek Polacek <polacek@redhat.com>
+
+ PR c++/55095
+ * c-common.c (maybe_warn_shift_overflow): Properly handle
+ left-shifting 1 into the sign bit.
+
2015-08-09 Manuel López-Ibáñez <manu@gcc.gnu.org>
* c.opt (Wchkp): Use LangEnabledBy instead of EnabledBy.
diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c
index f6c5ddd..13175d8 100644
--- a/gcc/c-family/c-common.c
+++ b/gcc/c-family/c-common.c
@@ -12442,9 +12442,10 @@ maybe_warn_shift_overflow (location_t loc, tree op0, tree op1)
if (TYPE_UNSIGNED (type0))
return false;
+ unsigned int min_prec = (wi::min_precision (op0, SIGNED)
+ + TREE_INT_CST_LOW (op1));
/* Handle the left-shifting 1 into the sign bit case. */
- if (integer_onep (op0)
- && compare_tree_int (op1, prec0 - 1) == 0)
+ if (min_prec == prec0 + 1)
{
/* Never warn for C++14 onwards. */
if (cxx_dialect >= cxx14)
@@ -12456,8 +12457,6 @@ maybe_warn_shift_overflow (location_t loc, tree op0, tree op1)
return true;
}
- unsigned int min_prec = (wi::min_precision (op0, SIGNED)
- + TREE_INT_CST_LOW (op1));
bool overflowed = min_prec > prec0;
if (overflowed && c_inhibit_evaluation_warnings == 0)
warning_at (loc, OPT_Wshift_overflow_,