mirror of
https://github.com/odin-lang/Odin.git
synced 2026-07-27 17:46:20 +00:00
Fix constant union stuff against tests
This commit is contained in:
@@ -117,33 +117,7 @@ gb_internal LLVMValueRef llvm_const_cast(lbModule *m, LLVMValueRef val, LLVMType
|
||||
unsigned dst_n = LLVMCountStructElementTypes(dst);
|
||||
if (src_n != dst_n) goto failure;
|
||||
|
||||
bool skip_cast = true;
|
||||
for (unsigned i = 0; i < dst_n; i++) {
|
||||
LLVMTypeKind dt = LLVMGetTypeKind(LLVMStructGetTypeAtIndex(dst, i));
|
||||
LLVMTypeKind st = LLVMGetTypeKind(LLVMStructGetTypeAtIndex(src, i));
|
||||
if (dt != st) {
|
||||
skip_cast = false;
|
||||
}
|
||||
if (dt == LLVMIntegerTypeKind) {
|
||||
continue;
|
||||
}
|
||||
if (dt != LLVMArrayTypeKind) {
|
||||
skip_cast = false;
|
||||
break;
|
||||
}
|
||||
|
||||
LLVMValueRef field_val = llvm_const_extract_value(m, val, i);
|
||||
if (field_val == nullptr) goto failure;
|
||||
|
||||
LLVMTypeRef dst_elem_ty = LLVMStructGetTypeAtIndex(dst, i);
|
||||
LLVMTypeRef src_elem_ty = LLVMTypeOf(field_val);
|
||||
if (lb_sizeof(dst_elem_ty) > lb_sizeof(src_elem_ty)) {
|
||||
skip_cast = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
}
|
||||
if (skip_cast) {
|
||||
if (LLVM_VERSION_MAJOR > 14) {
|
||||
return val;
|
||||
}
|
||||
|
||||
@@ -1075,7 +1049,7 @@ gb_internal lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, Ty
|
||||
values[value_count++] = llvm_const_pad_to_size(m, cv.value, block_type);
|
||||
#else
|
||||
values[value_count++] = cv.value;
|
||||
{
|
||||
if (block_size != type_size_of(variant_type)) {
|
||||
LLVMTypeRef padding_type = lb_type_padding_filler(m, block_size - type_size_of(variant_type), 1);
|
||||
values[value_count++] = LLVMConstNull(padding_type);
|
||||
}
|
||||
@@ -1095,6 +1069,7 @@ gb_internal lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, Ty
|
||||
}
|
||||
|
||||
res.value = LLVMConstStructInContext(m->ctx, values, value_count, true);
|
||||
gb_printf_err("%s\n", LLVMPrintValueToString(res.value));
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user