Fix constant union stuff against tests

This commit is contained in:
gingerBill
2026-06-29 13:00:44 +01:00
parent 2f3174fe10
commit b9a9846b7c
2 changed files with 22 additions and 45 deletions

View File

@@ -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;
}