From eb96fd6833536cf0437344c4bccafddc2df81803 Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Wed, 17 Apr 2013 11:21:01 +0300 Subject: [PATCH] parse: add a big hack to track packed structs Sparse doesn't handle packed structs correctly, and it still doesn't after this patch. But now I can query the is_packed attribute to find which structs are packed. Signed-off-by: Dan Carpenter --- parse.c | 5 +++++ symbol.h | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/parse.c b/parse.c index 38b2f785..51b25610 100644 --- a/parse.c +++ b/parse.c @@ -1020,6 +1020,7 @@ static struct token *ignore_attribute(struct token *token, struct symbol *attr, static struct token *attribute_packed(struct token *token, struct symbol *attr, struct decl_state *ctx) { + set_attr_is_packed(&ctx->ctype); if (!ctx->ctype.alignment) ctx->ctype.alignment = 1; return token; @@ -1237,6 +1238,10 @@ static struct token *attribute_specifier(struct token *token, struct decl_state token = expect(token, ')', "after attribute"); token = expect(token, ')', "after attribute"); + + if (ctx->ctype.attribute->is_packed && ctx->ctype.base_type) + set_attr_is_packed(&ctx->ctype.base_type->ctype); + return token; } diff --git a/symbol.h b/symbol.h index 63dc587e..eb259e35 100644 --- a/symbol.h +++ b/symbol.h @@ -83,6 +83,7 @@ extern struct context *alloc_context(void); struct attribute { struct context_list *contexts; unsigned int as; + unsigned int is_packed:1; }; @@ -426,6 +427,13 @@ static inline void merge_attr(struct ctype *dst, struct ctype *src) (struct ptr_list **)&attr->contexts); } +static inline void set_attr_is_packed(struct ctype *ctype) +{ + if (ctype->attribute == &null_attr) + ctype->attribute = __alloc_attribute(0); + ctype->attribute->is_packed = 1; +} + #define is_restricted_type(type) (get_sym_type(type) == SYM_RESTRICT) #define is_fouled_type(type) (get_sym_type(type) == SYM_FOULED) #define is_bitfield_type(type) (get_sym_type(type) == SYM_BITFIELD) -- 2.11.4.GIT