mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 07:38:48 +00:00
Fix #1883
This commit is contained in:
+20
-13
@@ -8404,23 +8404,30 @@ ExprKind check_compound_literal(CheckerContext *c, Operand *o, Ast *node, Type *
|
|||||||
if (is_type_bit_set(type)) {
|
if (is_type_bit_set(type)) {
|
||||||
// NOTE(bill): Encode as an integer
|
// NOTE(bill): Encode as an integer
|
||||||
|
|
||||||
i64 lower = base_type(type)->BitSet.lower;
|
Type *bt = base_type(type);
|
||||||
|
BigInt bits = {};
|
||||||
|
BigInt one = {};
|
||||||
|
big_int_from_u64(&one, 1);
|
||||||
|
|
||||||
u64 bits = 0;
|
for_array(i, cl->elems) {
|
||||||
for_array(index, cl->elems) {
|
Ast *e = cl->elems[i];
|
||||||
Ast *elem = cl->elems[index];
|
GB_ASSERT(e->kind != Ast_FieldValue);
|
||||||
GB_ASSERT(elem->kind != Ast_FieldValue);
|
|
||||||
TypeAndValue tav = elem->tav;
|
TypeAndValue tav = e->tav;
|
||||||
ExactValue i = exact_value_to_integer(tav.value);
|
if (tav.mode != Addressing_Constant) {
|
||||||
if (i.kind != ExactValue_Integer) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
i64 val = big_int_to_i64(&i.value_integer);
|
GB_ASSERT(tav.value.kind == ExactValue_Integer);
|
||||||
val -= lower;
|
i64 v = big_int_to_i64(&tav.value.value_integer);
|
||||||
u64 bit = u64(1ll<<val);
|
i64 lower = bt->BitSet.lower;
|
||||||
bits |= bit;
|
u64 index = cast(u64)(v-lower);
|
||||||
|
BigInt bit = {};
|
||||||
|
big_int_from_u64(&bit, index);
|
||||||
|
big_int_shl(&bit, &one, &bit);
|
||||||
|
big_int_or(&bits, &bits, &bit);
|
||||||
}
|
}
|
||||||
o->value = exact_value_u64(bits);
|
o->value.kind = ExactValue_Integer;
|
||||||
|
o->value.value_integer = bits;
|
||||||
} else if (is_type_constant_type(type) && cl->elems.count == 0) {
|
} else if (is_type_constant_type(type) && cl->elems.count == 0) {
|
||||||
ExactValue value = exact_value_compound(node);
|
ExactValue value = exact_value_compound(node);
|
||||||
Type *bt = core_type(type);
|
Type *bt = core_type(type);
|
||||||
|
|||||||
+11
-12
@@ -1025,7 +1025,10 @@ lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, bool allow_loc
|
|||||||
return lb_const_nil(m, original_type);
|
return lb_const_nil(m, original_type);
|
||||||
}
|
}
|
||||||
|
|
||||||
u64 bits = 0;
|
BigInt bits = {};
|
||||||
|
BigInt one = {};
|
||||||
|
big_int_from_u64(&one, 1);
|
||||||
|
|
||||||
for_array(i, cl->elems) {
|
for_array(i, cl->elems) {
|
||||||
Ast *e = cl->elems[i];
|
Ast *e = cl->elems[i];
|
||||||
GB_ASSERT(e->kind != Ast_FieldValue);
|
GB_ASSERT(e->kind != Ast_FieldValue);
|
||||||
@@ -1037,18 +1040,14 @@ lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, bool allow_loc
|
|||||||
GB_ASSERT(tav.value.kind == ExactValue_Integer);
|
GB_ASSERT(tav.value.kind == ExactValue_Integer);
|
||||||
i64 v = big_int_to_i64(&tav.value.value_integer);
|
i64 v = big_int_to_i64(&tav.value.value_integer);
|
||||||
i64 lower = type->BitSet.lower;
|
i64 lower = type->BitSet.lower;
|
||||||
bits |= 1ull<<cast(u64)(v-lower);
|
u64 index = cast(u64)(v-lower);
|
||||||
|
gb_printf_err("index: %llu\n", index);
|
||||||
|
BigInt bit = {};
|
||||||
|
big_int_from_u64(&bit, index);
|
||||||
|
big_int_shl(&bit, &one, &bit);
|
||||||
|
big_int_or(&bits, &bits, &bit);
|
||||||
}
|
}
|
||||||
if (is_type_different_to_arch_endianness(type)) {
|
res.value = lb_big_int_to_llvm(m, original_type, &bits);
|
||||||
i64 size = type_size_of(type);
|
|
||||||
switch (size) {
|
|
||||||
case 2: bits = cast(u64)gb_endian_swap16(cast(u16)bits); break;
|
|
||||||
case 4: bits = cast(u64)gb_endian_swap32(cast(u32)bits); break;
|
|
||||||
case 8: bits = cast(u64)gb_endian_swap64(cast(u64)bits); break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
res.value = LLVMConstInt(lb_type(m, original_type), bits, false);
|
|
||||||
return res;
|
return res;
|
||||||
} else if (is_type_matrix(type)) {
|
} else if (is_type_matrix(type)) {
|
||||||
ast_node(cl, CompoundLit, value.value_compound);
|
ast_node(cl, CompoundLit, value.value_compound);
|
||||||
|
|||||||
Reference in New Issue
Block a user