diff mbox

[C] Use warning_at (PR c/60087)

Message ID 20140206122456.GQ8907@redhat.com
State New
Headers show

Commit Message

Marek Polacek Feb. 6, 2014, 12:24 p.m. UTC
An obvious one, use location if available.  Can this be considered as
a "docfix" though, thus ok for trunk?  (Not a regression.)

Regtested/bootstrapped on x86_64-linux.

2014-02-06  Marek Polacek  <polacek@redhat.com>

	PR c/60087
c-family/
	* c-common.c (warn_for_sign_compare): Call warning_at with location
	instead of warning.
testsuite/
	* gcc.dg/pr60087.c: New test.


	Marek

Comments

Richard Biener Feb. 6, 2014, 1:30 p.m. UTC | #1
On Thu, Feb 6, 2014 at 1:24 PM, Marek Polacek <polacek@redhat.com> wrote:
> An obvious one, use location if available.  Can this be considered as
> a "docfix" though, thus ok for trunk?  (Not a regression.)
>
> Regtested/bootstrapped on x86_64-linux.

Ok.

Thanks,
Richard.

> 2014-02-06  Marek Polacek  <polacek@redhat.com>
>
>         PR c/60087
> c-family/
>         * c-common.c (warn_for_sign_compare): Call warning_at with location
>         instead of warning.
> testsuite/
>         * gcc.dg/pr60087.c: New test.
>
> diff --git gcc/c-family/c-common.c gcc/c-family/c-common.c
> index 007e727..50cc848 100644
> --- gcc/c-family/c-common.c
> +++ gcc/c-family/c-common.c
> @@ -11285,8 +11285,8 @@ warn_for_sign_compare (location_t location,
>                if ((mask & constant) != mask)
>                 {
>                   if (constant == 0)
> -                   warning (OPT_Wsign_compare,
> -                            "promoted ~unsigned is always non-zero");
> +                   warning_at (location, OPT_Wsign_compare,
> +                               "promoted ~unsigned is always non-zero");
>                   else
>                     warning_at (location, OPT_Wsign_compare,
>                                 "comparison of promoted ~unsigned with constant");
> diff --git gcc/testsuite/gcc.dg/pr60087.c gcc/testsuite/gcc.dg/pr60087.c
> index e69de29..9cdd589 100644
> --- gcc/testsuite/gcc.dg/pr60087.c
> +++ gcc/testsuite/gcc.dg/pr60087.c
> @@ -0,0 +1,14 @@
> +/* PR c/60087 */
> +/* { dg-do compile } */
> +/* { dg-options "-Wsign-compare" } */
> +
> +void
> +foo (unsigned int ui, int i)
> +{
> +  const unsigned char uc = 0;
> +  _Bool b;
> +  b = 0 != ~uc; /* { dg-warning "9:promoted ~unsigned is always non-zero" } */
> +  b = 2 != ~uc; /* { dg-warning "9:comparison of promoted ~unsigned with constant" } */
> +  b = uc == ~uc; /* { dg-warning "10:comparison of promoted ~unsigned with unsigned" } */
> +  b = i == ui; /* { dg-warning "9:comparison between signed and unsigned integer expressions" } */
> +}
>
>         Marek
diff mbox

Patch

diff --git gcc/c-family/c-common.c gcc/c-family/c-common.c
index 007e727..50cc848 100644
--- gcc/c-family/c-common.c
+++ gcc/c-family/c-common.c
@@ -11285,8 +11285,8 @@  warn_for_sign_compare (location_t location,
               if ((mask & constant) != mask)
 		{
 		  if (constant == 0)
-		    warning (OPT_Wsign_compare,
-			     "promoted ~unsigned is always non-zero");
+		    warning_at (location, OPT_Wsign_compare,
+				"promoted ~unsigned is always non-zero");
 		  else
 		    warning_at (location, OPT_Wsign_compare,
 				"comparison of promoted ~unsigned with constant");
diff --git gcc/testsuite/gcc.dg/pr60087.c gcc/testsuite/gcc.dg/pr60087.c
index e69de29..9cdd589 100644
--- gcc/testsuite/gcc.dg/pr60087.c
+++ gcc/testsuite/gcc.dg/pr60087.c
@@ -0,0 +1,14 @@ 
+/* PR c/60087 */
+/* { dg-do compile } */
+/* { dg-options "-Wsign-compare" } */
+
+void
+foo (unsigned int ui, int i)
+{
+  const unsigned char uc = 0;
+  _Bool b;
+  b = 0 != ~uc; /* { dg-warning "9:promoted ~unsigned is always non-zero" } */
+  b = 2 != ~uc; /* { dg-warning "9:comparison of promoted ~unsigned with constant" } */
+  b = uc == ~uc; /* { dg-warning "10:comparison of promoted ~unsigned with unsigned" } */
+  b = i == ui; /* { dg-warning "9:comparison between signed and unsigned integer expressions" } */
+}