All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3] warn on empty expressions
@ 2020-07-14  0:00 Luc Van Oostenryck
  2020-07-14  0:00 ` [PATCH 1/3] add testcase for incorrect " Luc Van Oostenryck
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Luc Van Oostenryck @ 2020-07-14  0:00 UTC (permalink / raw)
  To: linux-sparse; +Cc: Luc Van Oostenryck

Sparse silently accepts empty assignments and empty initializers.
This series makes them an error.

Luc Van Oostenryck (3):
  add testcase for incorrect empty expressions
  warn on empty assignments
  warn on empty initializations

 expression.c                   |  6 +++++-
 parse.c                        |  5 ++++-
 validation/bad-assignment.c    |  1 +
 validation/empty-assign.c      | 13 +++++++++++++
 validation/empty-initializer.c |  9 +++++++++
 5 files changed, 32 insertions(+), 2 deletions(-)
 create mode 100644 validation/empty-assign.c
 create mode 100644 validation/empty-initializer.c


base-commit: c9676a3b0349a1053c673243af52a2ef1b272bd7
-- 
2.27.0


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

* [PATCH 1/3] add testcase for incorrect empty expressions
  2020-07-14  0:00 [PATCH 0/3] warn on empty expressions Luc Van Oostenryck
@ 2020-07-14  0:00 ` Luc Van Oostenryck
  2020-07-14  0:00 ` [PATCH 2/3] warn on empty assignments Luc Van Oostenryck
  2020-07-14  0:00 ` [PATCH 3/3] warn on empty initializations Luc Van Oostenryck
  2 siblings, 0 replies; 4+ messages in thread
From: Luc Van Oostenryck @ 2020-07-14  0:00 UTC (permalink / raw)
  To: linux-sparse; +Cc: Luc Van Oostenryck

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 validation/empty-assign.c      | 14 ++++++++++++++
 validation/empty-initializer.c | 10 ++++++++++
 2 files changed, 24 insertions(+)
 create mode 100644 validation/empty-assign.c
 create mode 100644 validation/empty-initializer.c

diff --git a/validation/empty-assign.c b/validation/empty-assign.c
new file mode 100644
index 000000000000..48ac626ddaed
--- /dev/null
+++ b/validation/empty-assign.c
@@ -0,0 +1,14 @@
+static int foo(int a)
+{
+	a = ;			// KO
+	return a;
+}
+
+/*
+ * check-name: empty-assign
+ * check-known-to-fail
+ *
+ * check-error-start
+empty-assign.c:3:11: error: expression expected before ';'
+ * check-error-end
+ */
diff --git a/validation/empty-initializer.c b/validation/empty-initializer.c
new file mode 100644
index 000000000000..0ca763f699a0
--- /dev/null
+++ b/validation/empty-initializer.c
@@ -0,0 +1,10 @@
+static int i = ;		// KO
+
+/*
+ * check-name: empty-initializer
+ * check-known-to-fail
+ *
+ * check-error-start
+empty-initializer.c:1:16: error: expression expected before ';'
+ * check-error-end
+ */
-- 
2.27.0


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

* [PATCH 2/3] warn on empty assignments
  2020-07-14  0:00 [PATCH 0/3] warn on empty expressions Luc Van Oostenryck
  2020-07-14  0:00 ` [PATCH 1/3] add testcase for incorrect " Luc Van Oostenryck
@ 2020-07-14  0:00 ` Luc Van Oostenryck
  2020-07-14  0:00 ` [PATCH 3/3] warn on empty initializations Luc Van Oostenryck
  2 siblings, 0 replies; 4+ messages in thread
From: Luc Van Oostenryck @ 2020-07-14  0:00 UTC (permalink / raw)
  To: linux-sparse; +Cc: Luc Van Oostenryck

Currently sparse accepts an empty assignment like:
	a = ;

Make this an error.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 expression.c                | 6 +++++-
 validation/bad-assignment.c | 1 +
 validation/empty-assign.c   | 1 -
 3 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/expression.c b/expression.c
index 1160cd9cc593..ecbdd18eb402 100644
--- a/expression.c
+++ b/expression.c
@@ -937,10 +937,14 @@ struct token *assignment_expression(struct token *token, struct expression **tre
 		for (i = 0; i < ARRAY_SIZE(assignments); i++)
 			if (assignments[i] == op) {
 				struct expression * expr = alloc_expression(token->pos, EXPR_ASSIGNMENT);
+				struct token *next = token->next;
 				expr->left = *tree;
 				expr->op = op;
 				*tree = expr;
-				return assignment_expression(token->next, &expr->right);
+				token = assignment_expression(next, &expr->right);
+				if (token == next)
+					expression_error(expr, "expression expected before '%s'", show_token(token));
+				return token;
 			}
 	}
 	return token;
diff --git a/validation/bad-assignment.c b/validation/bad-assignment.c
index 71938db7c4f5..959712beda94 100644
--- a/validation/bad-assignment.c
+++ b/validation/bad-assignment.c
@@ -8,6 +8,7 @@ static int foo(int a)
  * check-name: bad assignment
  *
  * check-error-start
+bad-assignment.c:3:11: error: expression expected before '\'
 bad-assignment.c:3:13: error: Expected ; at end of statement
 bad-assignment.c:3:13: error: got \
  * check-error-end
diff --git a/validation/empty-assign.c b/validation/empty-assign.c
index 48ac626ddaed..d1c3884f71e8 100644
--- a/validation/empty-assign.c
+++ b/validation/empty-assign.c
@@ -6,7 +6,6 @@ static int foo(int a)
 
 /*
  * check-name: empty-assign
- * check-known-to-fail
  *
  * check-error-start
 empty-assign.c:3:11: error: expression expected before ';'
-- 
2.27.0


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

* [PATCH 3/3] warn on empty initializations
  2020-07-14  0:00 [PATCH 0/3] warn on empty expressions Luc Van Oostenryck
  2020-07-14  0:00 ` [PATCH 1/3] add testcase for incorrect " Luc Van Oostenryck
  2020-07-14  0:00 ` [PATCH 2/3] warn on empty assignments Luc Van Oostenryck
@ 2020-07-14  0:00 ` Luc Van Oostenryck
  2 siblings, 0 replies; 4+ messages in thread
From: Luc Van Oostenryck @ 2020-07-14  0:00 UTC (permalink / raw)
  To: linux-sparse; +Cc: Luc Van Oostenryck

Currently sparse accepts an empty initialization like:
	int a = ;

Make this an error.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 parse.c                        | 5 ++++-
 validation/empty-initializer.c | 1 -
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/parse.c b/parse.c
index a9222e7cbf08..d0a41b14b914 100644
--- a/parse.c
+++ b/parse.c
@@ -3117,7 +3117,10 @@ struct token *external_declaration(struct token *token, struct symbol_list **lis
 
 	for (;;) {
 		if (!is_typedef && match_op(token, '=')) {
-			token = initializer(&decl->initializer, token->next);
+			struct token *next = token->next;
+			token = initializer(&decl->initializer, next);
+			if (token == next)
+				sparse_error(token->pos, "expression expected before '%s'", show_token(token));
 		}
 		if (!is_typedef) {
 			if (validate_decl)
diff --git a/validation/empty-initializer.c b/validation/empty-initializer.c
index 0ca763f699a0..950679991401 100644
--- a/validation/empty-initializer.c
+++ b/validation/empty-initializer.c
@@ -2,7 +2,6 @@ static int i = ;		// KO
 
 /*
  * check-name: empty-initializer
- * check-known-to-fail
  *
  * check-error-start
 empty-initializer.c:1:16: error: expression expected before ';'
-- 
2.27.0


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

end of thread, other threads:[~2020-07-14  0:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-14  0:00 [PATCH 0/3] warn on empty expressions Luc Van Oostenryck
2020-07-14  0:00 ` [PATCH 1/3] add testcase for incorrect " Luc Van Oostenryck
2020-07-14  0:00 ` [PATCH 2/3] warn on empty assignments Luc Van Oostenryck
2020-07-14  0:00 ` [PATCH 3/3] warn on empty initializations Luc Van Oostenryck

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.