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@xxxxxxxxx> --- parse.c | 4 ++++ validation/context-stmt.c | 17 +++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/parse.c b/parse.c index cdf034dea..b4a7fef8a 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 8cea6b5f2..2884a8a21 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 -- 2.17.0 -- To unsubscribe from this list: send the line "unsubscribe linux-sparse" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html