harec

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

commit bbabe09bddf74bd699f8ad2224fdd6e2eefbd35e
parent df1dac2e0b31d222d5143d432f46b4412434302a
Author: Alexey Yerin <yyp@disroot.org>
Date:   Fri, 24 Jun 2022 19:06:10 +0300

gen: fix assertion failure when using uintptr enums in globals

Signed-off-by: Alexey Yerin <yyp@disroot.org>

Diffstat:
Msrc/gen.c | 5+++--
Mtests/15-enums.ha | 7+++++++
2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/src/gen.c b/src/gen.c @@ -3538,14 +3538,15 @@ gen_data_item(struct gen_context *ctx, struct expression *expr, break; case STORAGE_I32: case STORAGE_U32: - case STORAGE_INT: + case STORAGE_INT: // XXX: arch case STORAGE_UINT: item->type = QD_VALUE; item->value = constw((uint32_t)constant->uval); break; case STORAGE_U64: case STORAGE_I64: - case STORAGE_SIZE: + case STORAGE_SIZE: // XXX: arch + case STORAGE_UINTPTR: item->type = QD_VALUE; item->value = constl((uint64_t)constant->uval); break; diff --git a/tests/15-enums.ha b/tests/15-enums.ha @@ -46,6 +46,13 @@ type rune_storage = enum rune { BAR = '1', }; +type uintptr_storage = enum uintptr { + FOO = 0, + BAR = 1, +}; + +let global_uintptr: uintptr_storage = uintptr_storage::FOO; + fn storage() void = { assert(size(explicit_values) == size(int)); assert(size(with_storage) == 2);