linux-sparse.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
To: linux-sparse@vger.kernel.org
Cc: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Subject: [PATCH 2/3] warn on empty assignments
Date: Tue, 14 Jul 2020 02:00:29 +0200	[thread overview]
Message-ID: <20200714000030.85886-3-luc.vanoostenryck@gmail.com> (raw)
In-Reply-To: <20200714000030.85886-1-luc.vanoostenryck@gmail.com>

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


  parent reply	other threads:[~2020-07-14  0:00 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2020-07-14  0:00 ` [PATCH 3/3] warn on empty initializations Luc Van Oostenryck

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=20200714000030.85886-3-luc.vanoostenryck@gmail.com \
    --to=luc.vanoostenryck@gmail.com \
    --cc=linux-sparse@vger.kernel.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).