diff mbox

Possible bug with _Static_assert & sparse

Message ID CANeU7QkfSiU6WX_TND++E=zWNBeWWPTj7F722Kij1q=tKqmzgQ@mail.gmail.com (mailing list archive)
State Superseded, archived
Headers show

Commit Message

Christopher Li Aug. 2, 2014, 5:29 a.m. UTC
On Wed, Jul 30, 2014 at 10:32 AM, Mike Holmes <mike.holmes@linaro.org> wrote:
> Hi
>
> I wondered if the following sparse error indication was expected
> behaviour or if it is a bug,
> I would not expect sparse to error with "got 9"
>
>
> $ cat static.c
> #include <stdio.h>
>
> #define fake 9
> _Static_assert( fake > 8, "test message");
>


I create a patch to parse the _Static_assert and static_assert.
Because _Static_assert can happen on the top level declare. It is
not really a statement. My patch is not complete because
parse_static_assert() does not save the parsing result for later
evaluation. I need to figure out where to store it because it is
not a statement and it has no effect on back ends. Suggestions
are welcome.

Chris
diff mbox

Patch

diff --git a/parse.c b/parse.c
index 55a57a7..59fc934 100644
--- a/parse.c
+++ b/parse.c
@@ -73,6 +73,8 @@  static struct token *parse_context_statement(struct token *token, struct stateme
 static struct token *parse_range_statement(struct token *token, struct statement *stmt);
 static struct token *parse_asm_statement(struct token *token, struct statement *stmt);
 static struct token *toplevel_asm_declaration(struct token *token, struct symbol_list **list);
+static struct token *parse_static_assert_statement(struct token *token, struct statement *stmt);
+static struct token *toplevel_static_assert_declaration(struct token *token, struct symbol_list **list);
 
 typedef struct token *attr_t(struct token *, struct symbol *,
 			     struct decl_state *);
@@ -308,6 +310,11 @@  static struct symbol_op asm_op = {
 	.toplevel = toplevel_asm_declaration,
 };
 
+static struct symbol_op static_assert_op = {
+	.statement = parse_static_assert_statement,
+	.toplevel = toplevel_static_assert_declaration,
+};
+
 static struct symbol_op packed_op = {
 	.attribute = attribute_packed,
 };
@@ -460,6 +467,8 @@  static struct init_keyword {
 	{ "asm",	NS_KEYWORD, .op = &asm_op },
 	{ "__asm",	NS_KEYWORD, .op = &asm_op },
 	{ "__asm__",	NS_KEYWORD, .op = &asm_op },
+	{ "static_assert", NS_KEYWORD, .op = &static_assert_op },
+	{ "_Static_assert", NS_KEYWORD, .op = &static_assert_op },
 
 	/* Attribute */
 	{ "packed",	NS_KEYWORD, .op = &packed_op },
@@ -2003,6 +2012,29 @@  static struct token *parse_asm_declarator(struct token *token, struct decl_state
 	return token;
 }
 
+static struct token *parse_static_assert(struct token * token)
+{
+	struct expression *expr = NULL;
+
+	token = expect(token->next, '(', "after static assert");
+	token = conditional_expression(token, &expr);
+	token = expect(token, ',', "after constant expression of static assert");
+	token = parse_expression(token, &expr);
+	token = expect(token, ')', "after static assert");
+	return expect(token, ';', "at end of static assert");
+}
+
+static struct token *parse_static_assert_statement(struct token *token, struct statement *stmt)
+{
+	return parse_static_assert(token);
+}
+
+static struct token *toplevel_static_assert_declaration(struct token *token, struct symbol_list **list)
+{
+	return parse_static_assert(token);
+}
+
+
 /* Make a statement out of an expression */
 static struct statement *make_statement(struct expression *expr)
 {