diff options
| author | welinder@troll.com <welinder@troll.com> | 2004-08-24 14:52:45 -0700 |
|---|---|---|
| committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-07 21:02:52 -0700 |
| commit | 7fde376573db96adc9eae0403ef319af609201d7 (patch) | |
| tree | b89747e21f1af05c0d32b7889af43419125ebaa0 | |
| parent | 2746e07865f980650206b9ba057f3b37db8edc8b (diff) | |
| download | sparse-dev-7fde376573db96adc9eae0403ef319af609201d7.tar.gz | |
Disallow sizeof/alignof/typeof on bitfields.
| -rw-r--r-- | evaluate.c | 6 | ||||
| -rw-r--r-- | symbol.c | 2 | ||||
| -rw-r--r-- | symbol.h | 9 |
3 files changed, 14 insertions, 3 deletions
@@ -1528,6 +1528,8 @@ static struct symbol *evaluate_sizeof(struct expression *expr) if (!evaluate_expression(expr->cast_expression)) return NULL; size = expr->cast_expression->ctype->bit_size; + if (is_bitfield_type (expr->cast_expression->ctype)) + warn(expr->pos, "sizeof applied to bitfield type"); } if (size & 7) warn(expr->pos, "cannot size expression"); @@ -1546,6 +1548,8 @@ static struct symbol *evaluate_alignof(struct expression *expr) if (!type) return NULL; } + if (is_bitfield_type (expr->cast_expression->ctype)) + warn(expr->pos, "alignof applied to bitfield type"); examine_symbol_type(type); expr->type = EXPR_VALUE; expr->value = type->ctype.alignment; @@ -2120,8 +2124,6 @@ struct symbol *evaluate_return_expression(struct statement *stmt) static void evaluate_if_statement(struct statement *stmt) { - struct symbol *ctype; - if (!stmt->if_conditional) return; @@ -244,6 +244,8 @@ struct symbol *examine_symbol_type(struct symbol * sym) return sym; case SYM_TYPEOF: { struct symbol *base = evaluate_expression(sym->initializer); + if (is_bitfield_type (base)) + warn(base->pos, "typeof applied to bitfield type"); if (base) { if (base->type == SYM_NODE) base = base->ctype.base_type; @@ -227,7 +227,7 @@ extern void debug_symbol(struct symbol *); extern void merge_type(struct symbol *sym, struct symbol *base_type); extern void check_declaration(struct symbol *sym); -static inline int is_int_type(struct symbol *type) +static inline int is_int_type(const struct symbol *type) { if (type->type == SYM_NODE) type = type->ctype.base_type; @@ -236,4 +236,11 @@ static inline int is_int_type(struct symbol *type) type->ctype.base_type == &int_type; } +static inline int is_bitfield_type(const struct symbol *type) +{ + if (type->type == SYM_NODE) + type = type->ctype.base_type; + return (type->type == SYM_BITFIELD); +} + #endif /* SEMANTIC_H */ |
