summaryrefslogtreecommitdiffhomepage
path: root/ir/be/begnuas.c
diff options
context:
space:
mode:
authorMatthias Braun <matze@braunis.de>2015-09-07 19:54:07 +0200
committerMatthias Braun <matze@braunis.de>2015-09-07 19:56:45 +0200
commit5f595bc74cf0f88096db339616005046ff518132 (patch)
tree199a416d7ec9b1c27918575ef8965768542e121c /ir/be/begnuas.c
parent1eb94d6ddea22cdf0e34e227cb390178ddddf6ac (diff)
begnuas: Fix initializers of entities with vararg type getting omitted
Also do some cleanups like using unsigned long instead of size_t for the size (we are not talking about objects in the compiler so size_t is not apropriate).
Diffstat (limited to 'ir/be/begnuas.c')
-rw-r--r--ir/be/begnuas.c25
1 files changed, 18 insertions, 7 deletions
diff --git a/ir/be/begnuas.c b/ir/be/begnuas.c
index d992548..0795e31 100644
--- a/ir/be/begnuas.c
+++ b/ir/be/begnuas.c
@@ -916,9 +916,21 @@ static size_t get_initializer_size(const ir_initializer_t *initializer,
panic("found invalid initializer");
}
+static unsigned long compute_entity_size(ir_entity const *const entity)
+{
+ ir_type *const type = get_entity_type(entity);
+ unsigned long size = get_type_size_bytes(type);
+ /* Note that for variable array/compound types we may have to inspect the
+ * initializer to get the actualy size */
+ ir_initializer_t const *const initializer = get_entity_initializer(entity);
+ if (initializer != NULL)
+ size = get_initializer_size(initializer, type);
+ return size;
+}
+
#ifndef NDEBUG
static normal_or_bitfield *glob_vals;
-static size_t max_vals;
+static unsigned long max_vals;
#endif
static void emit_bitfield(normal_or_bitfield *vals, unsigned offset_bits,
@@ -991,7 +1003,7 @@ static void emit_ir_initializer(normal_or_bitfield *vals,
const ir_initializer_t *initializer,
ir_type *type)
{
- assert((size_t) (vals - glob_vals) <= max_vals);
+ assert((unsigned long) (vals - glob_vals) <= max_vals);
if (initializer_is_string_const(initializer, false)) {
assert(vals->kind != BITFIELD);
@@ -1129,7 +1141,8 @@ static void emit_node_data(ir_node *const init, ir_type *const type)
be_emit_write_line();
}
-static void emit_initializer(ir_entity const *const entity)
+static void emit_initializer(ir_entity const *const entity,
+ unsigned long const size)
{
ir_initializer_t const *const initializer = get_entity_initializer(entity);
if (initializer_is_string_const(initializer, false)) {
@@ -1138,7 +1151,6 @@ static void emit_initializer(ir_entity const *const entity)
}
ir_type *type = get_entity_type(entity);
- size_t size = get_initializer_size(initializer, type);
assert(size > 0);
/*
@@ -1442,8 +1454,7 @@ static void emit_global(be_main_env_t const *const main_env,
be_emit_write_line();
}
- ir_type *const type = get_entity_type(entity);
- unsigned const size = get_type_size_bytes(type);
+ unsigned long const size = compute_entity_size(entity);
if (size == 0) {
/* We need to output at least 1 byte, otherwise macho will merge
* the label with the next thing */
@@ -1460,7 +1471,7 @@ static void emit_global(be_main_env_t const *const main_env,
be_emit_irprintf("\t.space %u, 0\n", size);
be_emit_write_line();
} else {
- emit_initializer(entity);
+ emit_initializer(entity, size);
}
}
}