| ... | @@ -3218,7 +3218,8 @@ static LLVMValueRef ir_render_decl_var(CodeGen *g, IrExecutable *executable, | ... | @@ -3218,7 +3218,8 @@ static LLVMValueRef ir_render_decl_var(CodeGen *g, IrExecutable *executable, |
| 3218 | assert(var->value->type == init_value->value.type); | 3218 | assert(var->value->type == init_value->value.type); |
| 3219 | ZigType *var_ptr_type = get_pointer_to_type_extra(g, var->value->type, false, false, | 3219 | ZigType *var_ptr_type = get_pointer_to_type_extra(g, var->value->type, false, false, |
| 3220 | PtrLenSingle, var->align_bytes, 0, 0); | 3220 | PtrLenSingle, var->align_bytes, 0, 0); |
| 3221 | gen_assign_raw(g, var->value_ref, var_ptr_type, ir_llvm_value(g, init_value)); | 3221 | LLVMValueRef llvm_init_val = ir_llvm_value(g, init_value); |
| | 3222 | gen_assign_raw(g, var->value_ref, var_ptr_type, llvm_init_val); |
| 3222 | } else { | 3223 | } else { |
| 3223 | bool want_safe = ir_want_runtime_safety(g, &decl_var_instruction->base); | 3224 | bool want_safe = ir_want_runtime_safety(g, &decl_var_instruction->base); |
| 3224 | if (want_safe) { | 3225 | if (want_safe) { |
| ... | @@ -5863,12 +5864,20 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val, const c | ... | @@ -5863,12 +5864,20 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val, const c |
| 5863 | LLVMValueRef tag_value = bigint_to_llvm_const(type_entry->data.unionation.tag_type->type_ref, | 5864 | LLVMValueRef tag_value = bigint_to_llvm_const(type_entry->data.unionation.tag_type->type_ref, |
| 5864 | &const_val->data.x_union.tag); | 5865 | &const_val->data.x_union.tag); |
| 5865 | | 5866 | |
| 5866 | LLVMValueRef fields[2]; | 5867 | LLVMValueRef fields[3]; |
| 5867 | fields[type_entry->data.unionation.gen_union_index] = union_value_ref; | 5868 | fields[type_entry->data.unionation.gen_union_index] = union_value_ref; |
| 5868 | fields[type_entry->data.unionation.gen_tag_index] = tag_value; | 5869 | fields[type_entry->data.unionation.gen_tag_index] = tag_value; |
| 5869 | | 5870 | |
| 5870 | if (make_unnamed_struct) { | 5871 | if (make_unnamed_struct) { |
| 5871 | return LLVMConstStruct(fields, 2, false); | 5872 | LLVMValueRef result = LLVMConstStruct(fields, 2, false); |
| | 5873 | size_t expected_sz = LLVMStoreSizeOfType(g->target_data_ref, type_entry->type_ref); |
| | 5874 | size_t actual_sz = LLVMStoreSizeOfType(g->target_data_ref, LLVMTypeOf(result)); |
| | 5875 | if (actual_sz < expected_sz) { |
| | 5876 | unsigned pad_sz = expected_sz - actual_sz; |
| | 5877 | fields[2] = LLVMGetUndef(LLVMArrayType(LLVMInt8Type(), pad_sz)); |
| | 5878 | result = LLVMConstStruct(fields, 3, false); |
| | 5879 | } |
| | 5880 | return result; |
| 5872 | } else { | 5881 | } else { |
| 5873 | return LLVMConstNamedStruct(type_entry->type_ref, fields, 2); | 5882 | return LLVMConstNamedStruct(type_entry->type_ref, fields, 2); |
| 5874 | } | 5883 | } |