mie: stop using movable memory for mie_name instances.

any struct that contains a mie_name cannot be stored in movable memory
(i.e. any memory that may be re-allocated using realloc(), or whose
contents may be moved to a different buffer).

mie_names form part of a bst when they are added to a mie_name_map,
and moving them after this happens will result in the bst pointers
being invalidated. this causes some obscure and hard-to-debug
memory errors.

all structs that contain a mie_name (including named IR objects like
mie_register and mie_block) are no longer stored directly in vectors.
rather, vectors of pointers are used instead.
This commit is contained in:
2026-01-12 10:40:57 +00:00
parent 0fdadb3250
commit d19e8626da
9 changed files with 95 additions and 24 deletions

28
mie/ir/module.c Normal file
View File

@@ -0,0 +1,28 @@
#include <mie/ir/module.h>
#include <mie/ir/op.h>
#include <stdlib.h>
#include <string.h>
struct mie_module *mie_module_create(void)
{
struct mie_module *out = malloc(sizeof *out);
if (!out) {
return NULL;
}
memset(out, 0x0, sizeof *out);
out->m_names = mie_name_map_create(NULL);
return out;
}
void mie_module_destroy(struct mie_module *mod)
{
/* TODO */
}
struct mie_op *mie_module_add_op(struct mie_module *mod)
{
return mie_vector_emplace_back(mod->m_ops);
}

18
mie/ir/region.c Normal file
View File

@@ -0,0 +1,18 @@
#include <mie/ir/block.h>
#include <mie/ir/region.h>
#include <stdlib.h>
#include <string.h>
struct mie_block *mie_region_add_block(struct mie_region *region)
{
struct mie_block *block = malloc(sizeof *block);
if (!block) {
return NULL;
}
memset(block, 0x0, sizeof *block);
mie_vector_push_back(region->r_blocks, &block);
return block;
}