diff mbox

[C] Better column info for shift warnings (PR c/60351)

Message ID 20140425124538.GQ2103@redhat.com
State New
Headers show

Commit Message

Marek Polacek April 25, 2014, 12:45 p.m. UTC
A trivial patch to improve column info of warnings about shift count.

Tested x86_64-linux, ok for trunk?

2014-04-25  Marek Polacek  <polacek@redhat.com>

	PR c/60351
	* c-typeck.c (build_binary_op): Use location when warning about
	shift count.

	* gcc.dg/pr60351.c: New test.


	Marek

Comments

Richard Henderson April 29, 2014, 7:23 p.m. UTC | #1
On 04/25/2014 05:45 AM, Marek Polacek wrote:
> 2014-04-25  Marek Polacek  <polacek@redhat.com>
> 
> 	PR c/60351
> 	* c-typeck.c (build_binary_op): Use location when warning about
> 	shift count.
> 
> 	* gcc.dg/pr60351.c: New test.

Ok.


r~
diff mbox

Patch

diff --git gcc/c/c-typeck.c gcc/c/c-typeck.c
index 62c72df..e23c6db 100644
--- gcc/c/c-typeck.c
+++ gcc/c/c-typeck.c
@@ -10402,7 +10402,7 @@  build_binary_op (location_t location, enum tree_code code,
 		{
 		  int_const = false;
 		  if (c_inhibit_evaluation_warnings == 0)
-		    warning (0, "right shift count is negative");
+		    warning_at (location, 0, "right shift count is negative");
 		}
 	      else
 		{
@@ -10413,7 +10413,8 @@  build_binary_op (location_t location, enum tree_code code,
 		    {
 		      int_const = false;
 		      if (c_inhibit_evaluation_warnings == 0)
-			warning (0, "right shift count >= width of type");
+			warning_at (location, 0, "right shift count >= width "
+				    "of type");
 		    }
 		}
 	    }
@@ -10455,14 +10456,15 @@  build_binary_op (location_t location, enum tree_code code,
 		{
 		  int_const = false;
 		  if (c_inhibit_evaluation_warnings == 0)
-		    warning (0, "left shift count is negative");
+		    warning_at (location, 0, "left shift count is negative");
 		}
 
 	      else if (compare_tree_int (op1, TYPE_PRECISION (type0)) >= 0)
 		{
 		  int_const = false;
 		  if (c_inhibit_evaluation_warnings == 0)
-		    warning (0, "left shift count >= width of type");
+		    warning_at (location, 0, "left shift count >= width of "
+				"type");
 		}
 	    }
 
diff --git gcc/testsuite/gcc.dg/pr60351.c gcc/testsuite/gcc.dg/pr60351.c
index e69de29..29184d9 100644
--- gcc/testsuite/gcc.dg/pr60351.c
+++ gcc/testsuite/gcc.dg/pr60351.c
@@ -0,0 +1,11 @@ 
+/* PR c/60351 */
+/* { dg-do compile } */
+
+void
+f (int i)
+{
+  i >> -1; /* { dg-warning "5:right shift count is negative" } */
+  i >> 250; /* { dg-warning "5:right shift count >= width of type" } */
+  i << -1; /* { dg-warning "5:left shift count is negative" } */
+  i << 250; /* { dg-warning "5:left shift count >= width of type" } */
+}