linux-sparse.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] warn on implicit type
@ 2017-06-08  2:47 Luc Van Oostenryck
  2017-06-08  2:47 ` [PATCH 1/2] ret-void: add test case for toplevel asm Luc Van Oostenryck
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Luc Van Oostenryck @ 2017-06-08  2:47 UTC (permalink / raw)
  To: linux-sparse; +Cc: Chris Li, Luc Van Oostenryck

The goal of this mini-series is to warn about implicit.
It's part of a larger series whose goal is to straighten
situations where the return type of a function doesn't
match the type of what is returned, often silently and
with incoherence in the code generated.


This series can also be pulled from:
  git://github.com/lucvoo/sparse.git implicit-int

----------------------------------------------------------------
Luc Van Oostenryck (2):
      ret-void: add test case for toplevel asm
      ret-void: warn for implicit type

 parse.c                        |  9 +++++++++
 validation/alias-mixed.c       |  2 +-
 validation/asm-toplevel.c      |  7 +++++++
 validation/badtype2.c          |  1 +
 validation/implicit-ret-type.c | 15 +++++++++++++++
 validation/implicit-type.c     | 14 ++++++++++++++
 validation/typedef_shadow.c    |  1 +
 7 files changed, 48 insertions(+), 1 deletion(-)
 create mode 100644 validation/asm-toplevel.c
 create mode 100644 validation/implicit-ret-type.c
 create mode 100644 validation/implicit-type.c

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

* [PATCH 1/2] ret-void: add test case for toplevel asm
  2017-06-08  2:47 [PATCH 0/2] warn on implicit type Luc Van Oostenryck
@ 2017-06-08  2:47 ` Luc Van Oostenryck
  2017-06-08  2:47 ` [PATCH 2/2] ret-void: warn for implicit type Luc Van Oostenryck
  2017-06-08  6:16 ` [PATCH 0/2] warn on " Christopher Li
  2 siblings, 0 replies; 5+ messages in thread
From: Luc Van Oostenryck @ 2017-06-08  2:47 UTC (permalink / raw)
  To: linux-sparse; +Cc: Chris Li, Luc Van Oostenryck

Top-level asm is parsed as a fake anonymous function.
Obviously this fake function doesn't have a return type
and this create corner cases that need special handling.

For now, just add a test case with a top-leval asm to detect
possible problems in future code changes.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 validation/asm-toplevel.c | 7 +++++++
 1 file changed, 7 insertions(+)
 create mode 100644 validation/asm-toplevel.c

diff --git a/validation/asm-toplevel.c b/validation/asm-toplevel.c
new file mode 100644
index 000000000..8bdd7fc12
--- /dev/null
+++ b/validation/asm-toplevel.c
@@ -0,0 +1,7 @@
+__asm__("/* nothing */");
+/*
+ * check-name: asm-toplevel.c
+ * check-command: test-linearize $file
+ * check-output-ignore
+ * check-output-contains: asm *".. nothing .."
+ */
-- 
2.13.0


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

* [PATCH 2/2] ret-void: warn for implicit type
  2017-06-08  2:47 [PATCH 0/2] warn on implicit type Luc Van Oostenryck
  2017-06-08  2:47 ` [PATCH 1/2] ret-void: add test case for toplevel asm Luc Van Oostenryck
@ 2017-06-08  2:47 ` Luc Van Oostenryck
  2017-06-08  6:16 ` [PATCH 0/2] warn on " Christopher Li
  2 siblings, 0 replies; 5+ messages in thread
From: Luc Van Oostenryck @ 2017-06-08  2:47 UTC (permalink / raw)
  To: linux-sparse; +Cc: Chris Li, Luc Van Oostenryck

Currently, no warning is given for symbols for which no
type is explicitely given. But for functions we received
a pointless warning like here under if the returned type
is effectively an int:
	warning: incorrect type in return expression (invalid types)
	    expected incomplete type
	    got int

Fix this by issuing the warning.
Also give an implicit type of int, as required by C89, to
avoid pointless warning about the expected incomplete type.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 parse.c                        |  9 +++++++++
 validation/alias-mixed.c       |  2 +-
 validation/badtype2.c          |  1 +
 validation/implicit-ret-type.c | 15 +++++++++++++++
 validation/implicit-type.c     | 14 ++++++++++++++
 validation/typedef_shadow.c    |  1 +
 6 files changed, 41 insertions(+), 1 deletion(-)
 create mode 100644 validation/implicit-ret-type.c
 create mode 100644 validation/implicit-type.c

diff --git a/parse.c b/parse.c
index b08d4acef..214547904 100644
--- a/parse.c
+++ b/parse.c
@@ -2920,6 +2920,11 @@ struct token *external_declaration(struct token *token, struct symbol_list **lis
 			}
 		}
 	} else if (base_type && base_type->type == SYM_FN) {
+		if (base_type->ctype.base_type == &incomplete_ctype) {
+			warning(decl->pos, "'%s()' has implicit return type",
+				show_ident(decl->ident));
+			base_type->ctype.base_type = &int_ctype;
+		}
 		/* K&R argument declaration? */
 		if (lookup_type(token))
 			return parse_k_r_arguments(token, decl, list);
@@ -2931,6 +2936,10 @@ struct token *external_declaration(struct token *token, struct symbol_list **lis
 	} else if (base_type == &void_ctype && !(decl->ctype.modifiers & MOD_EXTERN)) {
 		sparse_error(token->pos, "void declaration");
 	}
+	if (base_type == &incomplete_ctype) {
+		warning(decl->pos, "'%s' has implicit type", show_ident(decl->ident));
+		decl->ctype.base_type = &int_ctype;;
+	}
 
 	for (;;) {
 		if (!is_typedef && match_op(token, '=')) {
diff --git a/validation/alias-mixed.c b/validation/alias-mixed.c
index 429304774..0cfbe36b8 100644
--- a/validation/alias-mixed.c
+++ b/validation/alias-mixed.c
@@ -15,7 +15,7 @@ static int bar(int *p)
 	return g == 1;
 }
 
-static test(void)
+static void test(void)
 {
 	foo(&g);
 	bar(&g);
diff --git a/validation/badtype2.c b/validation/badtype2.c
index 90a5fa1e4..49fec87ce 100644
--- a/validation/badtype2.c
+++ b/validation/badtype2.c
@@ -12,6 +12,7 @@ static undef foo(char *c)
 /*
  * check-name: missing type
  * check-error-start
+badtype2.c:2:8: warning: 'undef' has implicit type
 badtype2.c:2:14: error: Expected ; at end of declaration
 badtype2.c:2:14: error: got bar
 badtype2.c:3:14: error: Expected ; at end of declaration
diff --git a/validation/implicit-ret-type.c b/validation/implicit-ret-type.c
new file mode 100644
index 000000000..784a28531
--- /dev/null
+++ b/validation/implicit-ret-type.c
@@ -0,0 +1,15 @@
+fun(void);
+
+foo(void) { return 1; }
+static bar(void) { return 1; }
+
+/*
+ * check-name: implicit-ret-type.c
+ * check-command: sparse -Wno-decl $file
+ *
+ * check-error-start
+implicit-ret-type.c:1:1: warning: 'fun()' has implicit return type
+implicit-ret-type.c:3:1: warning: 'foo()' has implicit return type
+implicit-ret-type.c:4:8: warning: 'bar()' has implicit return type
+ * check-error-end
+ */
diff --git a/validation/implicit-type.c b/validation/implicit-type.c
new file mode 100644
index 000000000..724bab71e
--- /dev/null
+++ b/validation/implicit-type.c
@@ -0,0 +1,14 @@
+extern a;
+static b;
+c;
+
+/*
+ * check-name: implicit-type.c
+ * check-command: sparse -Wno-decl $file
+ *
+ * check-error-start
+implicit-type.c:1:8: warning: 'a' has implicit type
+implicit-type.c:2:8: warning: 'b' has implicit type
+implicit-type.c:3:1: warning: 'c' has implicit type
+ * check-error-end
+ */
diff --git a/validation/typedef_shadow.c b/validation/typedef_shadow.c
index c72cec72d..e52de80f2 100644
--- a/validation/typedef_shadow.c
+++ b/validation/typedef_shadow.c
@@ -6,6 +6,7 @@ static void f(int T)
 /*
  * check-name: typedef shadowing
  * check-error-start:
+typedef_shadow.c:4:16: warning: 'T' has implicit type
 typedef_shadow.c:4:18: error: Expected ; at end of declaration
 typedef_shadow.c:4:18: error: got a
  * check-error-end:
-- 
2.13.0


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

* Re: [PATCH 0/2] warn on implicit type
  2017-06-08  2:47 [PATCH 0/2] warn on implicit type Luc Van Oostenryck
  2017-06-08  2:47 ` [PATCH 1/2] ret-void: add test case for toplevel asm Luc Van Oostenryck
  2017-06-08  2:47 ` [PATCH 2/2] ret-void: warn for implicit type Luc Van Oostenryck
@ 2017-06-08  6:16 ` Christopher Li
  2017-06-08  7:25   ` Luc Van Oostenryck
  2 siblings, 1 reply; 5+ messages in thread
From: Christopher Li @ 2017-06-08  6:16 UTC (permalink / raw)
  To: Luc Van Oostenryck; +Cc: Linux-Sparse

On Wed, Jun 7, 2017 at 7:47 PM, Luc Van Oostenryck
<luc.vanoostenryck@gmail.com> wrote:
> The goal of this mini-series is to warn about implicit.
> It's part of a larger series whose goal is to straighten
> situations where the return type of a function doesn't
> match the type of what is returned, often silently and
> with incoherence in the code generated.

Looks good to me.

BTW, are those intend to merge into sparse-next or for
review only?

If it is for sparse-next. I kind of wish to have one dedicate
branch to pull from you. You can still have different branch
for review. It is just went I pull, I don't have to merge between
your branches.

Chris

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

* Re: [PATCH 0/2] warn on implicit type
  2017-06-08  6:16 ` [PATCH 0/2] warn on " Christopher Li
@ 2017-06-08  7:25   ` Luc Van Oostenryck
  0 siblings, 0 replies; 5+ messages in thread
From: Luc Van Oostenryck @ 2017-06-08  7:25 UTC (permalink / raw)
  To: Christopher Li; +Cc: Linux-Sparse

On Wed, Jun 07, 2017 at 11:16:27PM -0700, Christopher Li wrote:
> On Wed, Jun 7, 2017 at 7:47 PM, Luc Van Oostenryck
> <luc.vanoostenryck@gmail.com> wrote:
> > The goal of this mini-series is to warn about implicit.
> > It's part of a larger series whose goal is to straighten
> > situations where the return type of a function doesn't
> > match the type of what is returned, often silently and
> > with incoherence in the code generated.
> 
> Looks good to me.
> 
> BTW, are those intend to merge into sparse-next or for
> review only?

It's not something for the release, so for review only.
 
> If it is for sparse-next. I kind of wish to have one dedicate
> branch to pull from you. You can still have different branch
> for review. It is just went I pull, I don't have to merge between
> your branches.

Yes, understood.
Like for the previous ones, when it will be a pull request
it will be clearly so (with 'PULL' in the title and the output
of 'git request-pull' in the body).

-- Luc

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

end of thread, other threads:[~2017-06-08  7:25 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-06-08  2:47 [PATCH 0/2] warn on implicit type Luc Van Oostenryck
2017-06-08  2:47 ` [PATCH 1/2] ret-void: add test case for toplevel asm Luc Van Oostenryck
2017-06-08  2:47 ` [PATCH 2/2] ret-void: warn for implicit type Luc Van Oostenryck
2017-06-08  6:16 ` [PATCH 0/2] warn on " Christopher Li
2017-06-08  7:25   ` Luc Van Oostenryck

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).