On 04/22/2015 12:36 PM, Marek Polacek wrote:
Currently, we warn if the right operand of a shift expression is negative,
or greater than or equal to the length in bits of the promoted left operand.
But we don't warn when we see a left shift of a negative value. That is
undefined behavior since C99 and I believe C++11, so this patch implements
a new warning, -Wshift-negative-value, only active in C99/C++11.
A bunch of tests needed tweaking; I find it scary that some vect tests are
invoking UB.
Bootstrapped/regtested on x86_64-linux, ok for trunk?
2015-04-22 Marek Polacek <pola...@redhat.com>
PR c/65179
* c-common.c (c_fully_fold_internal): Warn when left shifting a
negative value.
* c.opt (Wshift-negative-value): New option.
* c-typeck.c (build_binary_op): Warn when left shifting a negative
value.
* typeck.c (cp_build_binary_op): Warn when left shifting a negative
value.
* doc/invoke.texi: Document -Wshift-negative-value.
* c-c++-common/Wshift-negative-value-1.c: New test.
* c-c++-common/Wshift-negative-value-2.c: New test.
* c-c++-common/torture/vector-shift2.c: Use -Wno-shift-negative-value.
* gcc.dg/torture/vector-shift2.c: Likewise.
* gcc.c-torture/execute/pr40386.c: Likewise.
* gcc.dg/tree-ssa/vrp65.c: Likewise.
* gcc.dg/tree-ssa/vrp66.c: Likewise.
* gcc.dg/vect/vect-sdivmod-1.c: Likewise.
* gcc.dg/vect/vect-shift-2-big-array.c: Likewise.
* gcc.dg/vect/vect-shift-2.c: Likewise.
* gcc.target/i386/pr31167.c: Likewise.
* g++.dg/init/array11.C: Add dg-warning.
* gcc.dg/c99-const-expr-7.c: Add dg-warning and dg-error.
OK.
jeff