All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] sparse: Make struct token::special signed
@ 2014-12-23 13:16 Rasmus Villemoes
  2014-12-23 19:01 ` Linus Torvalds
  0 siblings, 1 reply; 4+ messages in thread
From: Rasmus Villemoes @ 2014-12-23 13:16 UTC (permalink / raw)
  To: linux-sparse, Christopher Li; +Cc: Rasmus Villemoes

There doesn't seem to be any reason for the special member of struct
token to be unsigned; AFAICT it is only ever being directly compared
to explicit characters and the SPECIAL_* enum constants using ==, !=
and in a switch statement. Making it plain int avoids an annoying
warning from match_op in token.h when compiling with -Wsign-compare.

Signed-off-by: Rasmus Villemoes <rv@rasmusvillemoes.dk>
---
 token.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/token.h b/token.h
index 8dbd80f..69d95d7 100644
--- a/token.h
+++ b/token.h
@@ -187,7 +187,7 @@ struct token {
 	union {
 		const char *number;
 		struct ident *ident;
-		unsigned int special;
+		int special;
 		struct string *string;
 		int argnum;
 		struct argcount count;
-- 
2.1.3


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

* Re: [PATCH] sparse: Make struct token::special signed
  2014-12-23 13:16 [PATCH] sparse: Make struct token::special signed Rasmus Villemoes
@ 2014-12-23 19:01 ` Linus Torvalds
  2014-12-24  5:01   ` Benjamin Herrenschmidt
  0 siblings, 1 reply; 4+ messages in thread
From: Linus Torvalds @ 2014-12-23 19:01 UTC (permalink / raw)
  To: Rasmus Villemoes; +Cc: Sparse Mailing-list, Christopher Li

On Tue, Dec 23, 2014 at 5:16 AM, Rasmus Villemoes <rv@rasmusvillemoes.dk> wrote:
> There doesn't seem to be any reason for the special member of struct
> token to be unsigned; AFAICT it is only ever being directly compared
> to explicit characters and the SPECIAL_* enum constants using ==, !=
> and in a switch statement. Making it plain int avoids an annoying
> warning from match_op in token.h when compiling with -Wsign-compare.

Please don't use -Wsign-cpmpare to make decisions about code.

"unsigned" is generally the much preferred type if there are no
reasons for it to be signed. And -Wsign-compare on its own is not a
reason, since it gives insane warnings for good code.

-Wsign-compare is basically a "you can walk through the warnings and
see if any of them are actually valid" thing. It's not worth it in any
other form. Trying to be sign-compare clean will result in actively
*worse* code in some circumstances (ie pointless casts etc etc).

                     Linus

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

* Re: [PATCH] sparse: Make struct token::special signed
  2014-12-23 19:01 ` Linus Torvalds
@ 2014-12-24  5:01   ` Benjamin Herrenschmidt
  2014-12-24 11:07     ` Rasmus Villemoes
  0 siblings, 1 reply; 4+ messages in thread
From: Benjamin Herrenschmidt @ 2014-12-24  5:01 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: Rasmus Villemoes, Sparse Mailing-list, Christopher Li

On Tue, 2014-12-23 at 11:01 -0800, Linus Torvalds wrote:
> On Tue, Dec 23, 2014 at 5:16 AM, Rasmus Villemoes <rv@rasmusvillemoes.dk> wrote:
> > There doesn't seem to be any reason for the special member of struct
> > token to be unsigned; AFAICT it is only ever being directly compared
> > to explicit characters and the SPECIAL_* enum constants using ==, !=
> > and in a switch statement. Making it plain int avoids an annoying
> > warning from match_op in token.h when compiling with -Wsign-compare.
> 
> Please don't use -Wsign-cpmpare to make decisions about code.
> 
> "unsigned" is generally the much preferred type if there are no
> reasons for it to be signed. And -Wsign-compare on its own is not a
> reason, since it gives insane warnings for good code.
> 
> -Wsign-compare is basically a "you can walk through the warnings and
> see if any of them are actually valid" thing. It's not worth it in any
> other form. Trying to be sign-compare clean will result in actively
> *worse* code in some circumstances (ie pointless casts etc etc).

Additionally "compare with characters" trips another flag, chars are
unsigned by default on some archs :)

Cheers
Ben.

>                      Linus
> --
> To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html



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

* Re: [PATCH] sparse: Make struct token::special signed
  2014-12-24  5:01   ` Benjamin Herrenschmidt
@ 2014-12-24 11:07     ` Rasmus Villemoes
  0 siblings, 0 replies; 4+ messages in thread
From: Rasmus Villemoes @ 2014-12-24 11:07 UTC (permalink / raw)
  To: Benjamin Herrenschmidt
  Cc: Linus Torvalds, Sparse Mailing-list, Christopher Li

On Wed, Dec 24 2014, Benjamin Herrenschmidt <benh@kernel.crashing.org> wrote:

> On Tue, 2014-12-23 at 11:01 -0800, Linus Torvalds wrote:
>> On Tue, Dec 23, 2014 at 5:16 AM, Rasmus Villemoes <rv@rasmusvillemoes.dk> wrote:
>> > There doesn't seem to be any reason for the special member of struct
>> > token to be unsigned; AFAICT it is only ever being directly compared
>> > to explicit characters and the SPECIAL_* enum constants using ==, !=
>> > and in a switch statement. Making it plain int avoids an annoying
>> > warning from match_op in token.h when compiling with -Wsign-compare.
>> 
>> Please don't use -Wsign-cpmpare to make decisions about code.
>> 
>> "unsigned" is generally the much preferred type if there are no
>> reasons for it to be signed. And -Wsign-compare on its own is not a
>> reason, since it gives insane warnings for good code.
>> 
>> -Wsign-compare is basically a "you can walk through the warnings and
>> see if any of them are actually valid" thing. It's not worth it in any
>> other form. Trying to be sign-compare clean will result in actively
>> *worse* code in some circumstances (ie pointless casts etc etc).
>
> Additionally "compare with characters" trips another flag, chars are
> unsigned by default on some archs :)

And signed on others... if anything, that seems to be an argument _for_
the patch, since an int can always represent the entire range of char,
while that is not true for unsigned.

Anyway, I'm not going to pursue this further.

Rasmus

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

end of thread, other threads:[~2014-12-24 11:07 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-12-23 13:16 [PATCH] sparse: Make struct token::special signed Rasmus Villemoes
2014-12-23 19:01 ` Linus Torvalds
2014-12-24  5:01   ` Benjamin Herrenschmidt
2014-12-24 11:07     ` Rasmus Villemoes

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.