linux-sparse.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Kamil Dudka <kdudka@redhat.com>
To: Josh Triplett <josh@joshtriplett.org>
Cc: Christopher Li <sparse@chrisli.org>,
	Pavel Roskin <proski@gnu.org>,
	linux-sparse@vger.kernel.org
Subject: [PATCH] eliminate insane conversions from int to enum
Date: Sat, 27 Mar 2010 10:53:46 +0100	[thread overview]
Message-ID: <201003271053.47206.kdudka@redhat.com> (raw)
In-Reply-To: <20100327092949.GB9548@feather>

[-- Attachment #1: Type: text/plain, Size: 666 bytes --]

On Saturday 27 of March 2010 10:29:50 Josh Triplett wrote:
> > Here is what sparse gives:
> > $ ./sparse enum.c
> > enum.c:1:10: warning: non-ANSI function declaration of function 'main'
> > enum.c:6:15: warning: conversion of
> > enum.c:6:15:     int to
> > enum.c:6:15:     int enum <noident>
> >
> >
> > Here is what g++ gives:
> > $ g++ enum.c
> > enum.c: In function ‘int main()’:
> > enum.c:6: error: invalid conversion from ‘int’ to ‘main()::<anonymous
> > enum>’
>
> Yup, both of these warnings seem correct.  Don't fix them by casting,
> fix them by declaring "val" with an appropriate integral type.

patch attached

Kamil

[-- Attachment #2: 0001-eliminate-insane-conversions-from-int-to-enum.patch --]
[-- Type: text/x-diff, Size: 3461 bytes --]

From 44d964b9479affff31ad5690bedfe580ee3b50fa Mon Sep 17 00:00:00 2001
From: Kamil Dudka <kdudka@redhat.com>
Date: Sat, 27 Mar 2010 10:48:34 +0100
Subject: [PATCH] eliminate insane conversions from int to enum


Signed-off-by: Kamil Dudka <kdudka@redhat.com>
---
 expression.h |    1 -
 parse.c      |    2 +-
 parse.h      |    2 ++
 symbol.c     |    4 ++--
 symbol.h     |    8 ++++----
 5 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/expression.h b/expression.h
index 81f70ad..fe08a5f 100644
--- a/expression.h
+++ b/expression.h
@@ -206,7 +206,6 @@ static inline int lookup_type(struct token *token)
 }
 
 /* Statement parsing */
-struct statement *alloc_statement(struct position pos, int type);
 struct token *initializer(struct expression **tree, struct token *token);
 struct token *compound_statement(struct token *, struct statement *);
 
diff --git a/parse.c b/parse.c
index 7c6dce7..adaa132 100644
--- a/parse.c
+++ b/parse.c
@@ -613,7 +613,7 @@ static int SENTINEL_ATTR match_idents(struct token *token, ...)
 }
 
 
-struct statement *alloc_statement(struct position pos, int type)
+struct statement *alloc_statement(struct position pos, enum statement_type type)
 {
 	struct statement *stmt = __alloc_statement(0);
 	stmt->type = type;
diff --git a/parse.h b/parse.h
index 02b8585..6d51726 100644
--- a/parse.h
+++ b/parse.h
@@ -115,6 +115,8 @@ struct statement {
 	};
 };
 
+struct statement *alloc_statement(struct position pos, enum statement_type type);
+
 extern struct symbol_list *function_computed_target_list;
 extern struct statement_list *function_computed_goto_list;
 
diff --git a/symbol.c b/symbol.c
index 96dfbfa..8c46e20 100644
--- a/symbol.c
+++ b/symbol.c
@@ -39,12 +39,12 @@ void access_symbol(struct symbol *sym)
 	}
 }
 
-struct symbol *lookup_symbol(struct ident *ident, enum namespace ns)
+struct symbol *lookup_symbol(struct ident *ident, int ns_mask)
 {
 	struct symbol *sym;
 
 	for (sym = ident->symbols; sym; sym = sym->next_id) {
-		if (sym->namespace & ns) {
+		if (sym->namespace & ns_mask) {
 			sym->used = 1;
 			return sym;
 		}
diff --git a/symbol.h b/symbol.h
index e567305..7921aa1 100644
--- a/symbol.h
+++ b/symbol.h
@@ -97,7 +97,7 @@ struct decl_state {
 };
 
 struct symbol_op {
-	enum keyword type;
+	int type;
 	int (*evaluate)(struct expression *);
 	int (*expand)(struct expression *, int);
 	int (*args)(struct expression *);
@@ -267,7 +267,7 @@ extern void access_symbol(struct symbol *);
 extern const char * type_difference(struct ctype *c1, struct ctype *c2,
 	unsigned long mod1, unsigned long mod2);
 
-extern struct symbol *lookup_symbol(struct ident *, enum namespace);
+extern struct symbol *lookup_symbol(struct ident *, int ns_mask);
 extern struct symbol *create_symbol(int stream, const char *name, int type, int namespace);
 extern void init_symbols(void);
 extern void init_ctype(void);
@@ -367,11 +367,11 @@ static inline int get_sym_type(struct symbol *type)
 	return type->type;
 }
 
-static inline struct symbol *lookup_keyword(struct ident *ident, enum namespace ns)
+static inline struct symbol *lookup_keyword(struct ident *ident, int ns_mask)
 {
 	if (!ident->keyword)
 		return NULL;
-	return lookup_symbol(ident, ns);
+	return lookup_symbol(ident, ns_mask);
 }
 
 #define is_restricted_type(type) (get_sym_type(type) == SYM_RESTRICT)
-- 
1.7.0.2


  reply	other threads:[~2010-03-27  9:56 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-03-09  1:24 Sparse crash when mixing int and enum in ternary operator Pavel Roskin
2010-03-09  5:43 ` Christopher Li
2010-03-09 13:46   ` Kamil Dudka
2010-03-09 18:26     ` Pavel Roskin
2010-03-09 18:35     ` Pavel Roskin
2010-03-09 19:06       ` Kamil Dudka
2010-03-09 19:15         ` Josh Triplett
2010-03-09 20:11           ` Pavel Roskin
2010-03-09 20:29             ` Kamil Dudka
2010-03-09 23:30               ` Kamil Dudka
2010-03-10  1:09                 ` Pavel Roskin
2010-03-10 16:05                   ` Kamil Dudka
2010-03-10 20:27                     ` Pavel Roskin
2010-03-10 20:44                       ` Kamil Dudka
2010-03-10 21:03                       ` Kamil Dudka
2010-03-10 21:56                     ` Christopher Li
2010-03-13 17:22                       ` Kamil Dudka
2010-03-21 15:27                         ` Kamil Dudka
2010-03-24 10:07                           ` Christopher Li
2010-03-24 10:51                             ` Kamil Dudka
2010-03-27  9:16                             ` Kamil Dudka
2010-03-27  9:29                               ` Josh Triplett
2010-03-27  9:53                                 ` Kamil Dudka [this message]
2010-03-29 18:11                                   ` [PATCH] eliminate insane conversions from int to enum Christopher Li
2010-03-29 18:05                                 ` Sparse crash when mixing int and enum in ternary operator Christopher Li
2010-03-29 18:17                                   ` Kamil Dudka
2010-03-29 18:48                                     ` Christopher Li
2010-03-29 19:23                                       ` Kamil Dudka
2010-03-30  5:29                                         ` Pavel Roskin
2010-03-29 21:26                                   ` Josh Triplett

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=201003271053.47206.kdudka@redhat.com \
    --to=kdudka@redhat.com \
    --cc=josh@joshtriplett.org \
    --cc=linux-sparse@vger.kernel.org \
    --cc=proski@gnu.org \
    --cc=sparse@chrisli.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).