aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2018-05-26 13:58:03 +0200
committerLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2018-05-26 17:04:29 +0200
commitf88da50b475e3e5efdccfab1375ff6af6ae2b9ec (patch)
tree795087dab7afa95161286077b8403beeb463e283
parent63369a98d8ee0c72d28122539e4e542e62308ad2 (diff)
downloadsparse-dev-f88da50b475e3e5efdccfab1375ff6af6ae2b9ec.tar.gz
context: extra warning for __context__() & friends
Statements with an empty expression, like: __context__(); or __context__(x,); are silently accepted. Worse, since NULL expressions are usually ignored because it is assumed they have already been properly diagnosticated, no warnings of any kind are given at some later stage. Fix this by explicitly checking after empty expressions and emit an error message if needed. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
-rw-r--r--parse.c4
-rw-r--r--validation/context-stmt.c17
2 files changed, 21 insertions, 0 deletions
diff --git a/parse.c b/parse.c
index cdf034de..b4a7fef8 100644
--- a/parse.c
+++ b/parse.c
@@ -2341,10 +2341,14 @@ static struct token *parse_context_statement(struct token *token, struct stateme
token = token->next;
token = expect(token, '(', "after __context__ statement");
token = assignment_expression(token, &stmt->expression);
+ if (!stmt->expression)
+ unexpected(token, "expression expected after '('");
if (match_op(token, ',')) {
token = token->next;
stmt->context = stmt->expression;
token = assignment_expression(token, &stmt->expression);
+ if (!stmt->expression)
+ unexpected(token, "expression expected after ','");
}
token = expect(token, ')', "at end of __context__ statement");
return expect(token, ';', "at end of statement");
diff --git a/validation/context-stmt.c b/validation/context-stmt.c
index 8cea6b5f..2884a8a2 100644
--- a/validation/context-stmt.c
+++ b/validation/context-stmt.c
@@ -16,6 +16,11 @@ static void foo(int x)
__context__ x, 0); // KO: unmatched parens
__context__(0; // KO: unmatched parens
__context__ 0); // KO: unmatched parens
+
+ __context__(); // KO: no expression at all
+ __context__(,0); // KO: no expression at all
+ __context__(x,); // KO: no expression at all
+ __context__(,); // KO: no expression at all
}
/*
@@ -25,6 +30,8 @@ static void foo(int x)
* check-error-start
context-stmt.c:10:20: error: Expected ( after __context__ statement
context-stmt.c:10:20: error: got ;
+context-stmt.c:11:21: error: expression expected after '('
+context-stmt.c:11:21: error: got ;
context-stmt.c:11:21: error: Expected ) at end of __context__ statement
context-stmt.c:11:21: error: got ;
context-stmt.c:13:21: error: Expected ( after __context__ statement
@@ -39,6 +46,16 @@ context-stmt.c:17:22: error: Expected ) at end of __context__ statement
context-stmt.c:17:22: error: got ;
context-stmt.c:18:21: error: Expected ( after __context__ statement
context-stmt.c:18:21: error: got 0
+context-stmt.c:20:21: error: expression expected after '('
+context-stmt.c:20:21: error: got )
+context-stmt.c:21:21: error: expression expected after '('
+context-stmt.c:21:21: error: got ,
+context-stmt.c:22:23: error: expression expected after ','
+context-stmt.c:22:23: error: got )
+context-stmt.c:23:21: error: expression expected after '('
+context-stmt.c:23:21: error: got ,
+context-stmt.c:23:22: error: expression expected after ','
+context-stmt.c:23:22: error: got )
context-stmt.c:7:21: error: bad constant expression
context-stmt.c:8:23: error: bad constant expression
* check-error-end