harec

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

commit c6795a36c897dc809659b67c14d6f39dd28e9386
parent 0563d5ea64239a5434a4592763642158432ffcaf
Author: Eyal Sawady <ecs@d2evs.net>
Date:   Wed,  1 Dec 2021 05:08:28 +0000

check: fix exporting of global prototypes

Signed-off-by: Eyal Sawady <ecs@d2evs.net>

Diffstat:
Msrc/check.c | 29+++++++++++++++--------------
Msrc/gen.c | 3+++
2 files changed, 18 insertions(+), 14 deletions(-)

diff --git a/src/check.c b/src/check.c @@ -2965,13 +2965,24 @@ static struct declaration * check_global(struct context *ctx, const struct ast_global_decl *adecl) { - if (!adecl->init) { - return NULL; // Forward declaration - } - const struct type *type = type_store_lookup_atype( ctx->store, adecl->type); + struct declaration *decl = xcalloc(1, sizeof(struct declaration)); + decl->type = DECL_GLOBAL; + decl->global.type = type; + + if (adecl->symbol) { + decl->ident.name = strdup(adecl->symbol); + decl->symbol = strdup(adecl->symbol); + } else { + mkident(ctx, &decl->ident, &adecl->ident); + } + + if (!adecl->init) { + return decl; // Forward declaration + } + // TODO: Free initialier struct expression *initializer = xcalloc(1, sizeof(struct expression)); @@ -2990,18 +3001,8 @@ check_global(struct context *ctx, expect(&adecl->init->loc, r == EVAL_OK, "Unable to evaluate global initializer at compile time"); - struct declaration *decl = xcalloc(1, sizeof(struct declaration)); - decl->type = DECL_GLOBAL; - decl->global.type = type; decl->global.value = value; - if (adecl->symbol) { - decl->ident.name = strdup(adecl->symbol); - decl->symbol = strdup(adecl->symbol); - } else { - mkident(ctx, &decl->ident, &adecl->ident); - } - return decl; } diff --git a/src/gen.c b/src/gen.c @@ -3160,6 +3160,9 @@ gen_global_decl(struct gen_context *ctx, const struct declaration *decl) { assert(decl->type == DECL_GLOBAL); const struct global_decl *global = &decl->global; + if (!global->value) { + return; // Forward declaration + } struct qbe_def *qdef = xcalloc(1, sizeof(struct qbe_def)); qdef->kind = Q_DATA; qdef->exported = decl->exported;