aboutsummaryrefslogtreecommitdiff
path: root/gcc/c
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/c')
-rw-r--r--gcc/c/ChangeLog6
-rw-r--r--gcc/c/c-typeck.c11
2 files changed, 17 insertions, 0 deletions
diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog
index 2ef895a..ccd1e72 100644
--- a/gcc/c/ChangeLog
+++ b/gcc/c/ChangeLog
@@ -1,3 +1,9 @@
+2015-05-07 Marek Polacek <polacek@redhat.com>
+
+ PR c/65179
+ * c-typeck.c (build_binary_op): Warn when left shifting a negative
+ value.
+
2015-04-30 Marek Polacek <polacek@redhat.com>
* c-typeck.c (set_init_label): Call error_at instead of error and
diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c
index 328f294..73275aa 100644
--- a/gcc/c/c-typeck.c
+++ b/gcc/c/c-typeck.c
@@ -10697,6 +10697,17 @@ build_binary_op (location_t location, enum tree_code code,
&& code1 == INTEGER_TYPE)
{
doing_shift = true;
+ if (TREE_CODE (op0) == INTEGER_CST
+ && tree_int_cst_sgn (op0) < 0)
+ {
+ /* Don't reject a left shift of a negative value in a context
+ where a constant expression is needed in C90. */
+ if (flag_isoc99)
+ int_const = false;
+ if (c_inhibit_evaluation_warnings == 0)
+ warning_at (location, OPT_Wshift_negative_value,
+ "left shift of negative value");
+ }
if (TREE_CODE (op1) == INTEGER_CST)
{
if (tree_int_cst_sgn (op1) < 0)