| ... | ... | @@ -677,9 +677,14 @@ static LLVMValueRef ir_llvm_value(CodeGen *g, IrInstruction *instruction) { |
| 677 | 677 | assert(instruction->value.special != ConstValSpecialRuntime); |
| 678 | 678 | assert(instruction->value.type); |
| 679 | 679 | render_const_val(g, &instruction->value); |
| 680 | // we might have to do some pointer casting here due to the way union |
| 681 | // values are rendered with a type other than the one we expect |
| 680 | 682 | if (handle_is_ptr(instruction->value.type)) { |
| 681 | 683 | render_const_val_global(g, &instruction->value); |
| 682 | | instruction->llvm_value = instruction->value.llvm_global; |
| 684 | TypeTableEntry *ptr_type = get_pointer_to_type(g, instruction->value.type, true); |
| 685 | instruction->llvm_value = LLVMBuildBitCast(g->builder, instruction->value.llvm_global, ptr_type->type_ref, ""); |
| 686 | } else if (instruction->value.type->id == TypeTableEntryIdPointer) { |
| 687 | instruction->llvm_value = LLVMBuildBitCast(g->builder, instruction->value.llvm_value, instruction->value.type->type_ref, ""); |
| 683 | 688 | } else { |
| 684 | 689 | instruction->llvm_value = instruction->value.llvm_value; |
| 685 | 690 | } |
| ... | ... | @@ -2540,7 +2545,7 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val) { |
| 2540 | 2545 | tag_value, |
| 2541 | 2546 | union_value, |
| 2542 | 2547 | }; |
| 2543 | | return LLVMConstNamedStruct(canon_type->type_ref, fields, 2); |
| 2548 | return LLVMConstStruct(fields, 2, false); |
| 2544 | 2549 | } |
| 2545 | 2550 | } |
| 2546 | 2551 | case TypeTableEntryIdFn: |
| ... | ... | @@ -2553,11 +2558,7 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val) { |
| 2553 | 2558 | render_const_val(g, const_val->data.x_ptr.base_ptr); |
| 2554 | 2559 | render_const_val_global(g, const_val->data.x_ptr.base_ptr); |
| 2555 | 2560 | ConstExprValue *other_val = const_val->data.x_ptr.base_ptr; |
| 2556 | | if (other_val->type == const_val->type->data.pointer.child_type) { |
| 2557 | | const_val->llvm_value = other_val->llvm_global; |
| 2558 | | } else { |
| 2559 | | const_val->llvm_value = LLVMConstBitCast(other_val->llvm_global, const_val->type->type_ref); |
| 2560 | | } |
| 2561 | const_val->llvm_value = LLVMConstBitCast(other_val->llvm_global, const_val->type->type_ref); |
| 2561 | 2562 | render_const_val_global(g, const_val); |
| 2562 | 2563 | return const_val->llvm_value; |
| 2563 | 2564 | } else { |
| ... | ... | @@ -2636,7 +2637,8 @@ static void render_const_val(CodeGen *g, ConstExprValue *const_val) { |
| 2636 | 2637 | |
| 2637 | 2638 | static void render_const_val_global(CodeGen *g, ConstExprValue *const_val) { |
| 2638 | 2639 | if (!const_val->llvm_global) { |
| 2639 | | LLVMValueRef global_value = LLVMAddGlobal(g->module, const_val->type->type_ref, ""); |
| 2640 | LLVMTypeRef type_ref = const_val->llvm_value ? LLVMTypeOf(const_val->llvm_value) : const_val->type->type_ref; |
| 2641 | LLVMValueRef global_value = LLVMAddGlobal(g->module, type_ref, ""); |
| 2640 | 2642 | LLVMSetLinkage(global_value, LLVMInternalLinkage); |
| 2641 | 2643 | LLVMSetGlobalConstant(global_value, true); |
| 2642 | 2644 | LLVMSetUnnamedAddr(global_value, true); |