harec

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 4f5c228a41b0463bcb1c0934e887f044431526e9
parent a1a6ec6cd41923bcfde29730086b22fd97edd651
Author: Eyal Sawady <ecs@d2evs.net>
Date:   Sun, 14 Mar 2021 15:16:36 -0400

type_store_lookup_alias: update flagged aliases

Fixes the following:

let baz: *const foo = null: *const foo;

type foo = int;

export fn main() void = {
	*baz;
};

Diffstat:
Msrc/type_store.c | 32+++++++++++++++++++++++++-------
1 file changed, 25 insertions(+), 7 deletions(-)

diff --git a/src/type_store.c b/src/type_store.c @@ -779,14 +779,32 @@ type_store_lookup_alias(struct type_store *store, .align = secondary->align, .flags = secondary->flags, }; - struct type *type = (struct type *)type_store_lookup_type(store, &alias); - if (type->alias.type == NULL) { - // Finish filling in forward referenced type - type->alias.type = secondary; - type->size = secondary->size; - type->align = secondary->align; - type->flags = secondary->flags; + // XXX: This needs to be updated on updates to type_flags (types.h) + unsigned int flags[] = { + 0, + TYPE_CONST, + TYPE_ERROR, + TYPE_ERROR | TYPE_CONST, + }; + for (size_t i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) { + const struct type *flagged = type_store_lookup_with_flags(store, + secondary, flags[i]); + alias.flags = flagged->flags; + alias.alias.type = flagged; + struct type *falias = + (struct type *)type_store_lookup_type(store, &alias); + if (falias->alias.type == NULL) { + // Finish filling in forward referenced type + falias->alias.type = type_store_lookup_with_flags(store, + secondary, secondary->flags | flags[i]); + falias->size = secondary->size; + falias->align = secondary->align; + falias->flags = secondary->flags | flags[i]; + } } + alias.flags = secondary->flags; + alias.alias.type = secondary; + struct type *type = (struct type *)type_store_lookup_type(store, &alias); return type; }