From 6be4d3be2a2de03674501dd8d9a5c371d70a1aa0 Mon Sep 17 00:00:00 2001 From: Matthias Braun Date: Thu, 28 May 2009 10:51:29 +0000 Subject: [PATCH] fix remaining bitfield initializer problems [r26060] --- ast2firm.c | 20 ++++++++++++++++++-- parser.c | 5 ----- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/ast2firm.c b/ast2firm.c index 31262eb..b17c62d 100644 --- a/ast2firm.c +++ b/ast2firm.c @@ -79,6 +79,7 @@ static label_t **all_labels; static entity_t **inner_functions; static ir_node *ijmp_list; static bool constant_folding; +static bool initializer_use_bitfield_basetype; extern bool have_const_functions; @@ -3963,8 +3964,18 @@ static ir_initializer_t *create_ir_initializer_value( if (is_type_compound(initializer->value->base.type)) { panic("initializer creation for compounds not implemented yet"); } - ir_node *value = expression_to_firm(initializer->value); - type_t *type = initializer->value->base.type; + type_t *type = initializer->value->base.type; + expression_t *expr = initializer->value; + if (initializer_use_bitfield_basetype) { + type_t *skipped = skip_typeref(type); + if (skipped->kind == TYPE_BITFIELD) { + /* remove the bitfield cast... */ + assert(expr->kind == EXPR_UNARY_CAST_IMPLICIT); + expr = expr->unary.value; + type = skipped->bitfield.base_type; + } + } + ir_node *value = expression_to_firm(expr); ir_mode *mode = get_ir_mode_storage(type); value = create_conv(NULL, value, mode); return create_initializer_const(value); @@ -4246,8 +4257,13 @@ static void create_local_initializer(initializer_t *initializer, dbg_info *dbgi, } if (!is_constant_initializer(initializer)) { + bool old_initializer_use_bitfield_basetype + = initializer_use_bitfield_basetype; + initializer_use_bitfield_basetype = true; ir_initializer_t *irinitializer = create_ir_initializer(initializer, type); + initializer_use_bitfield_basetype + = old_initializer_use_bitfield_basetype; create_dynamic_initializer(irinitializer, dbgi, entity); return; diff --git a/parser.c b/parser.c index 71b027c..008d118 100644 --- a/parser.c +++ b/parser.c @@ -1840,11 +1840,6 @@ static initializer_t *initializer_from_expression(type_t *orig_type, &expression->base.source_position); initializer_t *const result = allocate_initializer_zero(INITIALIZER_VALUE); -#if 0 - if (type->kind == TYPE_BITFIELD) { - type = type->bitfield.base_type; - } -#endif result->value.value = create_implicit_cast(expression, type); return result; -- 2.20.1