| ... | ... | @@ -231,7 +231,7 @@ void codegen_set_linker_script(CodeGen *g, const char *linker_script) { |
| 231 | 231 | |
| 232 | 232 | |
| 233 | 233 | static void render_const_val(CodeGen *g, ConstExprValue *const_val); |
| 234 | | static void render_const_val_global(CodeGen *g, ConstExprValue *const_val); |
| 234 | static void render_const_val_global(CodeGen *g, ConstExprValue *const_val, const char *name); |
| 235 | 235 | |
| 236 | 236 | static LLVMValueRef fn_llvm_value(CodeGen *g, FnTableEntry *fn_table_entry) { |
| 237 | 237 | if (fn_table_entry->llvm_value) |
| ... | ... | @@ -686,7 +686,7 @@ static LLVMValueRef ir_llvm_value(CodeGen *g, IrInstruction *instruction) { |
| 686 | 686 | // we might have to do some pointer casting here due to the way union |
| 687 | 687 | // values are rendered with a type other than the one we expect |
| 688 | 688 | if (handle_is_ptr(instruction->value.type)) { |
| 689 | | render_const_val_global(g, &instruction->value); |
| 689 | render_const_val_global(g, &instruction->value, ""); |
| 690 | 690 | TypeTableEntry *ptr_type = get_pointer_to_type(g, instruction->value.type, true); |
| 691 | 691 | instruction->llvm_value = LLVMBuildBitCast(g->builder, instruction->value.llvm_global, ptr_type->type_ref, ""); |
| 692 | 692 | } else if (instruction->value.type->id == TypeTableEntryIdPointer) { |
| ... | ... | @@ -2425,7 +2425,7 @@ static LLVMValueRef gen_const_ptr_array_recursive(CodeGen *g, ConstExprValue *ar |
| 2425 | 2425 | base_ptr = gen_const_ptr_array_recursive(g, parent_array, parent_array_index); |
| 2426 | 2426 | } else { |
| 2427 | 2427 | render_const_val(g, array_const_val); |
| 2428 | | render_const_val_global(g, array_const_val); |
| 2428 | render_const_val_global(g, array_const_val, ""); |
| 2429 | 2429 | base_ptr = array_const_val->llvm_global; |
| 2430 | 2430 | } |
| 2431 | 2431 | TypeTableEntry *usize = g->builtin_types.entry_usize; |
| ... | ... | @@ -2573,16 +2573,16 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val) { |
| 2573 | 2573 | return fn_llvm_value(g, const_val->data.x_fn); |
| 2574 | 2574 | case TypeTableEntryIdPointer: |
| 2575 | 2575 | { |
| 2576 | | render_const_val_global(g, const_val); |
| 2576 | render_const_val_global(g, const_val, ""); |
| 2577 | 2577 | size_t index = const_val->data.x_ptr.index; |
| 2578 | 2578 | ConstExprValue *base_ptr = const_val->data.x_ptr.base_ptr; |
| 2579 | 2579 | if (base_ptr) { |
| 2580 | 2580 | if (index == SIZE_MAX) { |
| 2581 | 2581 | render_const_val(g, base_ptr); |
| 2582 | | render_const_val_global(g, base_ptr); |
| 2582 | render_const_val_global(g, base_ptr, ""); |
| 2583 | 2583 | ConstExprValue *other_val = base_ptr; |
| 2584 | 2584 | const_val->llvm_value = LLVMConstBitCast(other_val->llvm_global, const_val->type->type_ref); |
| 2585 | | render_const_val_global(g, const_val); |
| 2585 | render_const_val_global(g, const_val, ""); |
| 2586 | 2586 | return const_val->llvm_value; |
| 2587 | 2587 | } else { |
| 2588 | 2588 | ConstExprValue *array_const_val = base_ptr; |
| ... | ... | @@ -2592,19 +2592,19 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val) { |
| 2592 | 2592 | TypeTableEntry *usize = g->builtin_types.entry_usize; |
| 2593 | 2593 | const_val->llvm_value = LLVMConstIntToPtr(LLVMConstNull(usize->type_ref), |
| 2594 | 2594 | const_val->type->type_ref); |
| 2595 | | render_const_val_global(g, const_val); |
| 2595 | render_const_val_global(g, const_val, ""); |
| 2596 | 2596 | return const_val->llvm_value; |
| 2597 | 2597 | } |
| 2598 | 2598 | LLVMValueRef uncasted_ptr_val = gen_const_ptr_array_recursive(g, array_const_val, index); |
| 2599 | 2599 | LLVMValueRef ptr_val = LLVMConstBitCast(uncasted_ptr_val, const_val->type->type_ref); |
| 2600 | 2600 | const_val->llvm_value = ptr_val; |
| 2601 | | render_const_val_global(g, const_val); |
| 2601 | render_const_val_global(g, const_val, ""); |
| 2602 | 2602 | return ptr_val; |
| 2603 | 2603 | } |
| 2604 | 2604 | } else { |
| 2605 | 2605 | TypeTableEntry *usize = g->builtin_types.entry_usize; |
| 2606 | 2606 | const_val->llvm_value = LLVMConstIntToPtr(LLVMConstInt(usize->type_ref, index, false), const_val->type->type_ref); |
| 2607 | | render_const_val_global(g, const_val); |
| 2607 | render_const_val_global(g, const_val, ""); |
| 2608 | 2608 | return const_val->llvm_value; |
| 2609 | 2609 | } |
| 2610 | 2610 | } |
| ... | ... | @@ -2659,10 +2659,10 @@ static void render_const_val(CodeGen *g, ConstExprValue *const_val) { |
| 2659 | 2659 | LLVMSetInitializer(const_val->llvm_global, const_val->llvm_value); |
| 2660 | 2660 | } |
| 2661 | 2661 | |
| 2662 | | static void render_const_val_global(CodeGen *g, ConstExprValue *const_val) { |
| 2662 | static void render_const_val_global(CodeGen *g, ConstExprValue *const_val, const char *name) { |
| 2663 | 2663 | if (!const_val->llvm_global) { |
| 2664 | 2664 | LLVMTypeRef type_ref = const_val->llvm_value ? LLVMTypeOf(const_val->llvm_value) : const_val->type->type_ref; |
| 2665 | | LLVMValueRef global_value = LLVMAddGlobal(g->module, type_ref, ""); |
| 2665 | LLVMValueRef global_value = LLVMAddGlobal(g->module, type_ref, name); |
| 2666 | 2666 | LLVMSetLinkage(global_value, LLVMInternalLinkage); |
| 2667 | 2667 | LLVMSetGlobalConstant(global_value, true); |
| 2668 | 2668 | LLVMSetUnnamedAddr(global_value, true); |
| ... | ... | @@ -2846,7 +2846,7 @@ static void do_code_gen(CodeGen *g) { |
| 2846 | 2846 | LLVMSetLinkage(global_value, LLVMExternalLinkage); |
| 2847 | 2847 | } else { |
| 2848 | 2848 | render_const_val(g, &var->value); |
| 2849 | | render_const_val_global(g, &var->value); |
| 2849 | render_const_val_global(g, &var->value, buf_ptr(&var->name)); |
| 2850 | 2850 | global_value = var->value.llvm_global; |
| 2851 | 2851 | |
| 2852 | 2852 | if (var->linkage == VarLinkageExport) { |