linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* "unsigned expression < 0" always false warning
@ 2013-04-15 17:17 Bjorn Helgaas
  2013-04-19 20:43 ` Gary Hade
  2013-04-19 21:17 ` Steven Rostedt
  0 siblings, 2 replies; 6+ messages in thread
From: Bjorn Helgaas @ 2013-04-15 17:17 UTC (permalink / raw)
  To: Steven Rostedt, Frederic Weisbecker, Ingo Molnar; +Cc: linux-pci, Lance Ortiz

Can somebody help me resolve the following warning, please?

$ make W=1 drivers/pci/pcie/aer/aerdrv_errprint.o
...
  CC      drivers/pci/pcie/aer/aerdrv_errprint.o
In file included from include/trace/ftrace.h:356:0,
                 from include/trace/define_trace.h:86,
                 from include/trace/events/ras.h:77,
                 from drivers/pci/pcie/aer/aerdrv_errprint.c:27:
include/trace/events/ras.h: In function ‘ftrace_define_fields_aer_event’:
include/trace/events/ras.h:72:1: warning: comparison of unsigned
expression < 0 is always false [-Wtype-limits]

I think it's related to "status" being a u32 below (this is from
include/trace/events/ras.h), but I don't know whether that's incorrect
or how to fix it:

TRACE_EVENT(aer_event,
        TP_PROTO(const char *dev_name,
                 const u32 status,
                 const u8 severity),

        TP_ARGS(dev_name, status, severity),

        TP_STRUCT__entry(
                __string(       dev_name,       dev_name        )
                __field(        u32,            status          )
                __field(        u8,             severity        )
        ),
        ...

Thanks,
  Bjorn

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: "unsigned expression < 0" always false warning
  2013-04-15 17:17 "unsigned expression < 0" always false warning Bjorn Helgaas
@ 2013-04-19 20:43 ` Gary Hade
  2013-04-19 21:05   ` Steven Rostedt
  2013-04-19 21:17 ` Steven Rostedt
  1 sibling, 1 reply; 6+ messages in thread
From: Gary Hade @ 2013-04-19 20:43 UTC (permalink / raw)
  To: Bjorn Helgaas
  Cc: Steven Rostedt, Frederic Weisbecker, Ingo Molnar, linux-pci, Lance Ortiz

On Mon, Apr 15, 2013 at 11:17:31AM -0600, Bjorn Helgaas wrote:
> Can somebody help me resolve the following warning, please?
> 
> $ make W=1 drivers/pci/pcie/aer/aerdrv_errprint.o
> ...
>   CC      drivers/pci/pcie/aer/aerdrv_errprint.o
> In file included from include/trace/ftrace.h:356:0,
>                  from include/trace/define_trace.h:86,
>                  from include/trace/events/ras.h:77,
>                  from drivers/pci/pcie/aer/aerdrv_errprint.c:27:
> include/trace/events/ras.h: In function ‘ftrace_define_fields_aer_event’:
> include/trace/events/ras.h:72:1: warning: comparison of unsigned
> expression < 0 is always false [-Wtype-limits]
> 
> I think it's related to "status" being a u32 below (this is from
> include/trace/events/ras.h), but I don't know whether that's incorrect
> or how to fix it:
> 
> TRACE_EVENT(aer_event,
>         TP_PROTO(const char *dev_name,
>                  const u32 status,
>                  const u8 severity),
> 
>         TP_ARGS(dev_name, status, severity),
> 
>         TP_STRUCT__entry(
>                 __string(       dev_name,       dev_name        )
>                 __field(        u32,            status          )
>                 __field(        u8,             severity        )
>         ),
>         ...

The culrpit is the is_signed_type macro defined in
include/linux/ftrace_event.h:
  #define is_signed_type(type)    (((type)(-1)) < (type)0)

The above
  "__field(        u32,            status          )"
gets expanded to
  "ret = trace_define_field(event_call, "u32", "status", __builtin_offsetof(typeof(field),status), sizeof(field.status), (((u32)(-1)) < (u32)0), FILTER_OTHER); if (ret) return ret;"

The warning is triggered by:
  "(((u32)(-1)) < (u32)0)"
which was put there by is_signed_type.

It appears that is_signed_type is simply taking advantage of the same
action that the compiler is warning about to perform it's function.

Not sure how to make is_signed_type warningless although
it does create a significant amount of noise during a full
`make W=1` kernel build.  With 3.9-rc7 it appears to be
responsible for 1401 of 1476 occurrences of "warning: comparison
of unsigned expression < 0 is always false".

Gary


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: "unsigned expression < 0" always false warning
  2013-04-19 20:43 ` Gary Hade
@ 2013-04-19 21:05   ` Steven Rostedt
  0 siblings, 0 replies; 6+ messages in thread
From: Steven Rostedt @ 2013-04-19 21:05 UTC (permalink / raw)
  To: Gary Hade
  Cc: Bjorn Helgaas, Frederic Weisbecker, Ingo Molnar, linux-pci, Lance Ortiz

On Fri, 2013-04-19 at 13:43 -0700, Gary Hade wrote:

> The above
>   "__field(        u32,            status          )"
> gets expanded to
>   "ret = trace_define_field(event_call, "u32", "status", __builtin_offsetof(typeof(field),status), sizeof(field.status), (((u32)(-1)) < (u32)0), FILTER_OTHER); if (ret) return ret;"
> 
> The warning is triggered by:
>   "(((u32)(-1)) < (u32)0)"
> which was put there by is_signed_type.
> 
> It appears that is_signed_type is simply taking advantage of the same
> action that the compiler is warning about to perform it's function.

Yeah, that's the point of the macro.

> 
> Not sure how to make is_signed_type warningless although
> it does create a significant amount of noise during a full
> `make W=1` kernel build.  With 3.9-rc7 it appears to be
> responsible for 1401 of 1476 occurrences of "warning: comparison
> of unsigned expression < 0 is always false".

Since it is complaining about being less than zero, I just checked, the
following also works.

#define is_signed_type(type) ((type)-1 < (type)1)

And doesn't give the warning.

I'll go make a patch.

Thanks!

-- Steve



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: "unsigned expression < 0" always false warning
  2013-04-15 17:17 "unsigned expression < 0" always false warning Bjorn Helgaas
  2013-04-19 20:43 ` Gary Hade
@ 2013-04-19 21:17 ` Steven Rostedt
  2013-04-19 22:30   ` Bjorn Helgaas
  1 sibling, 1 reply; 6+ messages in thread
From: Steven Rostedt @ 2013-04-19 21:17 UTC (permalink / raw)
  To: Bjorn Helgaas
  Cc: Frederic Weisbecker, Ingo Molnar, linux-pci, Lance Ortiz, Gary Hade

Does this fix your issue?

-- Steve

>From d2802d0739dcc61af5e5ea00773ce7ddead4e9c2 Mon Sep 17 00:00:00 2001
From: "Steven Rostedt (Red Hat)" <rostedt@goodmis.org>
Date: Fri, 19 Apr 2013 17:10:27 -0400
Subject: [PATCH] tracing: Compare to 1 instead of zero for is_signed_type()

The formats of the trace events show if the type of a event field
is signed or not via a macro called is_signed_type(). This does
a trick with the type and compares a -1 to zero after typecasting
to the tested type. If it returns true, it's signed, otherwise
its not. But this unfortunately triggers a warning by gcc:

  warning: comparison of unsigned expression < 0 is always false

As we know it is always false (that's why we do it), this is a
false warning. Luckily for us, the comparison works with a 1 as
well, without giving the warning.

Convert the check to compare (type)-1 < (type)0 to (type)-1 < (type)1
to determine if the type is signed or not.

Link: http://lkml.kernel.org/r/CAErSpo4YXcY9fuOKWYGDkddJwk68kmZTohsmVB6QvrhjboOh1Q@mail.gmail.com

Reported-by: Bjorn Helgaas <bhelgaas@google.com>
Reported-by: Gary Hade <garyhade@us.ibm.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
---
 include/linux/ftrace_event.h |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
index 4e28b01..34e00fb 100644
--- a/include/linux/ftrace_event.h
+++ b/include/linux/ftrace_event.h
@@ -333,7 +333,7 @@ extern int trace_define_field(struct ftrace_event_call *call, const char *type,
 extern int trace_add_event_call(struct ftrace_event_call *call);
 extern void trace_remove_event_call(struct ftrace_event_call *call);
 
-#define is_signed_type(type)	(((type)(-1)) < (type)0)
+#define is_signed_type(type)	(((type)(-1)) < (type)1)
 
 int trace_set_clr_event(const char *system, const char *event, int set);
 
-- 
1.7.10.4




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: "unsigned expression < 0" always false warning
  2013-04-19 21:17 ` Steven Rostedt
@ 2013-04-19 22:30   ` Bjorn Helgaas
  2013-04-19 22:45     ` Gary Hade
  0 siblings, 1 reply; 6+ messages in thread
From: Bjorn Helgaas @ 2013-04-19 22:30 UTC (permalink / raw)
  To: Steven Rostedt
  Cc: Frederic Weisbecker, Ingo Molnar, linux-pci, Lance Ortiz, Gary Hade

On Fri, Apr 19, 2013 at 3:17 PM, Steven Rostedt <rostedt@goodmis.org> wrote:
> Does this fix your issue?

Yep, that fixes the warning for me.  Thanks!

Bjorn

> From d2802d0739dcc61af5e5ea00773ce7ddead4e9c2 Mon Sep 17 00:00:00 2001
> From: "Steven Rostedt (Red Hat)" <rostedt@goodmis.org>
> Date: Fri, 19 Apr 2013 17:10:27 -0400
> Subject: [PATCH] tracing: Compare to 1 instead of zero for is_signed_type()
>
> The formats of the trace events show if the type of a event field
> is signed or not via a macro called is_signed_type(). This does
> a trick with the type and compares a -1 to zero after typecasting
> to the tested type. If it returns true, it's signed, otherwise
> its not. But this unfortunately triggers a warning by gcc:
>
>   warning: comparison of unsigned expression < 0 is always false
>
> As we know it is always false (that's why we do it), this is a
> false warning. Luckily for us, the comparison works with a 1 as
> well, without giving the warning.
>
> Convert the check to compare (type)-1 < (type)0 to (type)-1 < (type)1
> to determine if the type is signed or not.
>
> Link: http://lkml.kernel.org/r/CAErSpo4YXcY9fuOKWYGDkddJwk68kmZTohsmVB6QvrhjboOh1Q@mail.gmail.com
>
> Reported-by: Bjorn Helgaas <bhelgaas@google.com>
> Reported-by: Gary Hade <garyhade@us.ibm.com>
> Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
> ---
>  include/linux/ftrace_event.h |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
> index 4e28b01..34e00fb 100644
> --- a/include/linux/ftrace_event.h
> +++ b/include/linux/ftrace_event.h
> @@ -333,7 +333,7 @@ extern int trace_define_field(struct ftrace_event_call *call, const char *type,
>  extern int trace_add_event_call(struct ftrace_event_call *call);
>  extern void trace_remove_event_call(struct ftrace_event_call *call);
>
> -#define is_signed_type(type)   (((type)(-1)) < (type)0)
> +#define is_signed_type(type)   (((type)(-1)) < (type)1)
>
>  int trace_set_clr_event(const char *system, const char *event, int set);
>
> --
> 1.7.10.4
>
>
>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: "unsigned expression < 0" always false warning
  2013-04-19 22:30   ` Bjorn Helgaas
@ 2013-04-19 22:45     ` Gary Hade
  0 siblings, 0 replies; 6+ messages in thread
From: Gary Hade @ 2013-04-19 22:45 UTC (permalink / raw)
  To: Bjorn Helgaas
  Cc: Steven Rostedt, Frederic Weisbecker, Ingo Molnar, linux-pci,
	Lance Ortiz, Gary Hade

On Fri, Apr 19, 2013 at 04:30:14PM -0600, Bjorn Helgaas wrote:
> On Fri, Apr 19, 2013 at 3:17 PM, Steven Rostedt <rostedt@goodmis.org> wrote:
> > Does this fix your issue?
> 
> Yep, that fixes the warning for me.  Thanks!
> 
> Bjorn

It also worked for me.  It got rid of every one the 1401 is_signed_type
associated "warning: comparison of unsigned expression < 0 is always false"
occurrences (during 3.9-rc7 `make W=1` kernel build) mentioned in my
previous email.

Gary

> 
> > From d2802d0739dcc61af5e5ea00773ce7ddead4e9c2 Mon Sep 17 00:00:00 2001
> > From: "Steven Rostedt (Red Hat)" <rostedt@goodmis.org>
> > Date: Fri, 19 Apr 2013 17:10:27 -0400
> > Subject: [PATCH] tracing: Compare to 1 instead of zero for is_signed_type()
> >
> > The formats of the trace events show if the type of a event field
> > is signed or not via a macro called is_signed_type(). This does
> > a trick with the type and compares a -1 to zero after typecasting
> > to the tested type. If it returns true, it's signed, otherwise
> > its not. But this unfortunately triggers a warning by gcc:
> >
> >   warning: comparison of unsigned expression < 0 is always false
> >
> > As we know it is always false (that's why we do it), this is a
> > false warning. Luckily for us, the comparison works with a 1 as
> > well, without giving the warning.
> >
> > Convert the check to compare (type)-1 < (type)0 to (type)-1 < (type)1
> > to determine if the type is signed or not.
> >
> > Link: http://lkml.kernel.org/r/CAErSpo4YXcY9fuOKWYGDkddJwk68kmZTohsmVB6QvrhjboOh1Q@mail.gmail.com
> >
> > Reported-by: Bjorn Helgaas <bhelgaas@google.com>
> > Reported-by: Gary Hade <garyhade@us.ibm.com>
> > Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
> > ---
> >  include/linux/ftrace_event.h |    2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
> > index 4e28b01..34e00fb 100644
> > --- a/include/linux/ftrace_event.h
> > +++ b/include/linux/ftrace_event.h
> > @@ -333,7 +333,7 @@ extern int trace_define_field(struct ftrace_event_call *call, const char *type,
> >  extern int trace_add_event_call(struct ftrace_event_call *call);
> >  extern void trace_remove_event_call(struct ftrace_event_call *call);
> >
> > -#define is_signed_type(type)   (((type)(-1)) < (type)0)
> > +#define is_signed_type(type)   (((type)(-1)) < (type)1)
> >
> >  int trace_set_clr_event(const char *system, const char *event, int set);
> >
> > --
> > 1.7.10.4
> >
> >
> >
> 


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2013-04-19 22:46 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-04-15 17:17 "unsigned expression < 0" always false warning Bjorn Helgaas
2013-04-19 20:43 ` Gary Hade
2013-04-19 21:05   ` Steven Rostedt
2013-04-19 21:17 ` Steven Rostedt
2013-04-19 22:30   ` Bjorn Helgaas
2013-04-19 22:45     ` Gary Hade

This is a public inbox, see mirroring instructions
on how to clone and mirror all data and code used for this inbox