aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
authorwelinder@troll.com <welinder@troll.com>2004-08-24 14:52:45 -0700
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-07 21:02:52 -0700
commit7fde376573db96adc9eae0403ef319af609201d7 (patch)
treeb89747e21f1af05c0d32b7889af43419125ebaa0
parent2746e07865f980650206b9ba057f3b37db8edc8b (diff)
downloadsparse-dev-7fde376573db96adc9eae0403ef319af609201d7.tar.gz
Disallow sizeof/alignof/typeof on bitfields.
-rw-r--r--evaluate.c6
-rw-r--r--symbol.c2
-rw-r--r--symbol.h9
3 files changed, 14 insertions, 3 deletions
diff --git a/evaluate.c b/evaluate.c
index 77a54d79..cc148ae0 100644
--- a/evaluate.c
+++ b/evaluate.c
@@ -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;
diff --git a/symbol.c b/symbol.c
index 0baa637a..5f9570d9 100644
--- a/symbol.c
+++ b/symbol.c
@@ -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;
diff --git a/symbol.h b/symbol.h
index 09f00d84..b0c17216 100644
--- a/symbol.h
+++ b/symbol.h
@@ -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 */