mirror of
https://github.com/odin-lang/Odin.git
synced 2026-07-11 02:19:30 +00:00
Merge branch 'master' into bill/constant-union-fixes
This commit is contained in:
@@ -1636,32 +1636,23 @@ gb_internal lbValue lb_emit_union_tag_ptr(lbProcedure *p, lbValue u) {
|
||||
GB_ASSERT_MSG(is_type_pointer(t) &&
|
||||
is_type_union(type_deref(t)), "%s", type_to_string(t));
|
||||
Type *ut = type_deref(t);
|
||||
Type *bt = base_type(ut);
|
||||
|
||||
GB_ASSERT(!is_type_union_maybe_pointer_original_alignment(ut));
|
||||
GB_ASSERT(!is_type_union_maybe_pointer(ut));
|
||||
GB_ASSERT(type_size_of(ut) > 0);
|
||||
GB_ASSERT(bt->kind == Type_Union);
|
||||
|
||||
Type *tag_type = union_tag_type(ut);
|
||||
|
||||
LLVMTypeRef uvt = llvm_addr_type(p->module, u);
|
||||
unsigned element_count = LLVMCountStructElementTypes(uvt);
|
||||
// if (LLVM_VERSION_MAJOR == 14 || bt->Union.variants.count == 1) {
|
||||
GB_ASSERT_MSG(element_count >= 2, "element_count=%u (%s) != (%s)", element_count, type_to_string(ut), LLVMPrintTypeToString(uvt));
|
||||
// } else {
|
||||
// GB_ASSERT_MSG(element_count >= 3, "element_count=%u (%s) != (%s)", element_count, type_to_string(ut), LLVMPrintTypeToString(uvt));
|
||||
// }
|
||||
GB_ASSERT_MSG(element_count >= 2, "element_count=%u (%s) != (%s)", element_count, type_to_string(ut), LLVMPrintTypeToString(uvt));
|
||||
|
||||
|
||||
LLVMValueRef ptr = u.value;
|
||||
ptr = LLVMBuildPointerCast(p->builder, ptr, LLVMPointerType(uvt, 0), "");
|
||||
|
||||
lbValue tag_ptr = {};
|
||||
// if (LLVM_VERSION_MAJOR == 14 || bt->Union.variants.count == 1) {
|
||||
tag_ptr.value = LLVMBuildStructGEP2(p->builder, uvt, ptr, 1, "");
|
||||
// } else {
|
||||
// tag_ptr.value = LLVMBuildStructGEP2(p->builder, uvt, ptr, 2, "");
|
||||
// }
|
||||
tag_ptr.value = LLVMBuildStructGEP2(p->builder, uvt, ptr, 1, "");
|
||||
tag_ptr.type = alloc_type_pointer(tag_type);
|
||||
tag_ptr.value = LLVMBuildPointerCast(p->builder, tag_ptr.value, lb_type(p->module, tag_ptr.type), "");
|
||||
return tag_ptr;
|
||||
@@ -2508,6 +2499,7 @@ gb_internal LLVMTypeRef lb_type_internal(lbModule *m, Type *type) {
|
||||
LLVMTypeRef fields[] = {lb_type(m, type->Union.variants[0])};
|
||||
return LLVMStructTypeInContext(ctx, fields, gb_count_of(fields), false);
|
||||
}
|
||||
bool is_packed = false;
|
||||
|
||||
auto fields = array_make<LLVMTypeRef>(temporary_allocator(), 0, 4);
|
||||
if (is_type_union_maybe_pointer(type)) {
|
||||
@@ -2525,6 +2517,7 @@ gb_internal LLVMTypeRef lb_type_internal(lbModule *m, Type *type) {
|
||||
LLVMTypeRef padding_type = lb_type_padding_filler(m, padding, align);
|
||||
array_add(&fields, padding_type);
|
||||
}
|
||||
is_packed = true;
|
||||
} else {
|
||||
LLVMTypeRef block_type = lb_type_internal_union_block_type(m, type);
|
||||
|
||||
@@ -2537,9 +2530,10 @@ gb_internal LLVMTypeRef lb_type_internal(lbModule *m, Type *type) {
|
||||
LLVMTypeRef padding_type = lb_type_padding_filler(m, padding, align);
|
||||
array_add(&fields, padding_type);
|
||||
}
|
||||
is_packed = true;
|
||||
}
|
||||
|
||||
return LLVMStructTypeInContext(ctx, fields.data, cast(unsigned)fields.count, /*packed*/true);
|
||||
return LLVMStructTypeInContext(ctx, fields.data, cast(unsigned)fields.count, is_packed);
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user