Skip to contentSkip to conversation

__attribute__ annotations and struct types

DISCUSSION Daniel Drake 4 participants 5 messages Feb 14, 2007 – Feb 23, 2007 Sparse checker

lore
Share & tools
lore
#0 lore raw

gcc-4.1.1 accepts this as valid code:

struct __attribute__((__aligned__(16))) foo {
    int a;
};

sparse doesn't like it:

test.c:7:8: error: Trying to use reserved word '__attribute__' as identifier

I'm not sure if this is a bug that people are interested in solving, as the more common form works in both gcc and sparse:

struct foo {
    int a;
} __attribute__((__aligned__(16)));

Thanks,

Signature · 2 lines
Daniel Drake
Brontes Technologies, A 3M Company
maintainer
#1 lore raw
Quoted 4 lines · Daniel Drake

sparse doesn't like it:

test.c:7:8: error: Trying to use reserved word '__attribute__' as identifier

Can you please try this:

Chris

Handle structure attribute.

struct __attribute__((__aligned__(16))) foo {
    int a;
};
parse.c +2 -0
Index: sparse/parse.c
===================================================================
@@ -34,6 +34,7 @@ struct symbol_list *function_computed_ta
 struct statement_list *function_computed_goto_list;
 
 static struct token *statement(struct token *token, struct statement **tree);
+static struct token *handle_attributes(struct token *token, struct ctype *ctype);
 
 // Add a symbol to the list of function-local symbols
 static void fn_local_symbol(struct symbol *sym)
@@ -156,6 +157,7 @@ static struct token *struct_union_enum_s
 	struct position *repos;
 
 	ctype->modifiers = 0;
+	token = handle_attributes(token, ctype);
 	if (token_type(token) == TOKEN_IDENT) {
 		sym = lookup_symbol(token->ident, NS_STRUCT);
 		if (!sym ||
#2 lore raw
Quoted 11 lines · Christopher Li
Quoted 4 lines · Daniel Drake

sparse doesn't like it:

test.c:7:8: error: Trying to use reserved word '__attribute__' as identifier

Can you please try this:

Chris

Handle structure attribute.

Thanks for the quick response, works nicely!

Signature · 2 lines
Daniel Drake
Brontes Technologies, A 3M Company
#3 lore raw
Quoted 7 lines · On Wed, 14 Feb 2007 16:02:07 -0500 Daniel Drake wrote:
Quoted 6 lines · Christopher Li
Quoted 4 lines · Daniel Drake

sparse doesn't like it:

test.c:7:8: error: Trying to use reserved word '__attribute__' as identifier

Quoted 7 lines
Quoted 5 lines

Can you please try this:

Chris

Handle structure attribute.

Thanks for the quick response, works nicely!

so now drivers/kvm/* should be less nasty ;)

---
~Randy
*** Remember to use Documentation/SubmitChecklist when testing your code ***

#4 lore raw
In reply to Daniel Drake
Quoted 6 lines · Daniel Drake
Quoted 5 lines · Christopher Li
Quoted 4 lines · Daniel Drake

sparse doesn't like it:

test.c:7:8: error: Trying to use reserved word '__attribute__' as identifier

Quoted 7 lines
Quoted 5 lines

Can you please try this:

Chris

Handle structure attribute.

Thanks for the quick response, works nicely!

Applied, along with a test case.

- Josh Triplett