harec

[hare] Hare compiler, written in C11 for POSIX OSs
Log | Files | Refs | README | LICENSE

commit 521d77191bcf208a1dc8a6bb3387fe859faf43b3
parent 72b8a8dc244cdd244c47237808fc6a32096436c7
Author: Drew DeVault <sir@cmpwn.com>
Date:   Sat,  4 Jun 2022 14:05:39 +0200

typedef: emit casts for uintptr enums

Signed-off-by: Drew DeVault <sir@cmpwn.com>

Diffstat:
Msrc/check.c | 5++++-
Msrc/typedef.c | 7++++++-
2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/src/check.c b/src/check.c @@ -3472,7 +3472,10 @@ scan_enum_field(struct context *ctx, struct incomplete_declaration *idecl) handle_errors(ctx->errors); expect(&idecl->field->field->value->loc, type_is_assignable(type->alias.type, initializer->result), - "Enum value type is not assignable from initializer type"); + "Enum value type (%s) is not assignable from initializer type (%s) for value %s", + gen_typename(type->alias.type), + gen_typename(initializer->result), + idecl->obj.ident.name); initializer = lower_implicit_cast(type, initializer); enum eval_result r = eval_expr(ctx, initializer, value); diff --git a/src/typedef.c b/src/typedef.c @@ -129,7 +129,12 @@ emit_const(const struct expression *expr, FILE *out) if (ev->otype == O_SCAN) { continue; } - if (ev->type->alias.type->storage == STORAGE_CHAR + if (ev->type->alias.type->storage == STORAGE_UINTPTR) { + if (ev->value->constant.uval == val->uval) { + fprintf(out, "(%" PRIuMAX "): uintptr", val->uval); + break; + } + } else if (ev->type->alias.type->storage == STORAGE_CHAR || !type_is_signed(ev->type->alias.type)) { if (ev->value->constant.uval == val->uval) { fprintf(out, "%" PRIuMAX, val->uval);