| ... | ... | @@ -283,9 +283,9 @@ void codegen_set_linker_script(CodeGen *g, const char *linker_script) { |
| 283 | 283 | } |
| 284 | 284 | |
| 285 | 285 | |
| 286 | | static void render_const_val(CodeGen *g, ConstExprValue *const_val); |
| 286 | static void render_const_val(CodeGen *g, ConstExprValue *const_val, const char *name); |
| 287 | 287 | static void render_const_val_global(CodeGen *g, ConstExprValue *const_val, const char *name); |
| 288 | | static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val); |
| 288 | static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val, const char *name); |
| 289 | 289 | static void generate_error_name_table(CodeGen *g); |
| 290 | 290 | |
| 291 | 291 | static void addLLVMAttr(LLVMValueRef val, LLVMAttributeIndex attr_index, const char *attr_name) { |
| ... | ... | @@ -874,7 +874,7 @@ static LLVMValueRef get_panic_msg_ptr_val(CodeGen *g, PanicMsgId msg_id) { |
| 874 | 874 | ConstExprValue *array_val = create_const_str_lit(g, buf_msg); |
| 875 | 875 | init_const_slice(g, val, array_val, 0, buf_len(buf_msg), true); |
| 876 | 876 | |
| 877 | | render_const_val(g, val); |
| 877 | render_const_val(g, val, ""); |
| 878 | 878 | render_const_val_global(g, val, ""); |
| 879 | 879 | |
| 880 | 880 | assert(val->global_refs->llvm_global); |
| ... | ... | @@ -1413,7 +1413,7 @@ static LLVMValueRef ir_llvm_value(CodeGen *g, IrInstruction *instruction) { |
| 1413 | 1413 | if (!instruction->llvm_value) { |
| 1414 | 1414 | assert(instruction->value.special != ConstValSpecialRuntime); |
| 1415 | 1415 | assert(instruction->value.type); |
| 1416 | | render_const_val(g, &instruction->value); |
| 1416 | render_const_val(g, &instruction->value, ""); |
| 1417 | 1417 | // we might have to do some pointer casting here due to the way union |
| 1418 | 1418 | // values are rendered with a type other than the one we expect |
| 1419 | 1419 | if (handle_is_ptr(instruction->value.type)) { |
| ... | ... | @@ -3892,7 +3892,7 @@ static LLVMValueRef gen_const_ptr_union_recursive(CodeGen *g, ConstExprValue *ar |
| 3892 | 3892 | static LLVMValueRef gen_parent_ptr(CodeGen *g, ConstExprValue *val, ConstParent *parent) { |
| 3893 | 3893 | switch (parent->id) { |
| 3894 | 3894 | case ConstParentIdNone: |
| 3895 | | render_const_val(g, val); |
| 3895 | render_const_val(g, val, ""); |
| 3896 | 3896 | render_const_val_global(g, val, ""); |
| 3897 | 3897 | return val->global_refs->llvm_global; |
| 3898 | 3898 | case ConstParentIdStruct: |
| ... | ... | @@ -3991,17 +3991,17 @@ static LLVMValueRef pack_const_int(CodeGen *g, LLVMTypeRef big_int_type_ref, Con |
| 3991 | 3991 | case TypeTableEntryIdEnum: |
| 3992 | 3992 | { |
| 3993 | 3993 | assert(type_entry->data.enumeration.decl_node->data.container_decl.init_arg_expr != nullptr); |
| 3994 | | LLVMValueRef int_val = gen_const_val(g, const_val); |
| 3994 | LLVMValueRef int_val = gen_const_val(g, const_val, ""); |
| 3995 | 3995 | return LLVMConstZExt(int_val, big_int_type_ref); |
| 3996 | 3996 | } |
| 3997 | 3997 | case TypeTableEntryIdInt: |
| 3998 | 3998 | { |
| 3999 | | LLVMValueRef int_val = gen_const_val(g, const_val); |
| 3999 | LLVMValueRef int_val = gen_const_val(g, const_val, ""); |
| 4000 | 4000 | return LLVMConstZExt(int_val, big_int_type_ref); |
| 4001 | 4001 | } |
| 4002 | 4002 | case TypeTableEntryIdFloat: |
| 4003 | 4003 | { |
| 4004 | | LLVMValueRef float_val = gen_const_val(g, const_val); |
| 4004 | LLVMValueRef float_val = gen_const_val(g, const_val, ""); |
| 4005 | 4005 | LLVMValueRef int_val = LLVMConstFPToUI(float_val, |
| 4006 | 4006 | LLVMIntType((unsigned)type_entry->data.floating.bit_count)); |
| 4007 | 4007 | return LLVMConstZExt(int_val, big_int_type_ref); |
| ... | ... | @@ -4010,7 +4010,7 @@ static LLVMValueRef pack_const_int(CodeGen *g, LLVMTypeRef big_int_type_ref, Con |
| 4010 | 4010 | case TypeTableEntryIdFn: |
| 4011 | 4011 | case TypeTableEntryIdMaybe: |
| 4012 | 4012 | { |
| 4013 | | LLVMValueRef ptr_val = gen_const_val(g, const_val); |
| 4013 | LLVMValueRef ptr_val = gen_const_val(g, const_val, ""); |
| 4014 | 4014 | LLVMValueRef ptr_size_int_val = LLVMConstPtrToInt(ptr_val, g->builtin_types.entry_usize->type_ref); |
| 4015 | 4015 | return LLVMConstZExt(ptr_size_int_val, big_int_type_ref); |
| 4016 | 4016 | } |
| ... | ... | @@ -4055,7 +4055,7 @@ static bool is_llvm_value_unnamed_type(TypeTableEntry *type_entry, LLVMValueRef |
| 4055 | 4055 | return LLVMTypeOf(val) != type_entry->type_ref; |
| 4056 | 4056 | } |
| 4057 | 4057 | |
| 4058 | | static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val) { |
| 4058 | static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val, const char *name) { |
| 4059 | 4059 | TypeTableEntry *type_entry = const_val->type; |
| 4060 | 4060 | assert(!type_entry->zero_bits); |
| 4061 | 4061 | |
| ... | ... | @@ -4108,7 +4108,7 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val) { |
| 4108 | 4108 | child_type->id == TypeTableEntryIdFn) |
| 4109 | 4109 | { |
| 4110 | 4110 | if (const_val->data.x_maybe) { |
| 4111 | | return gen_const_val(g, const_val->data.x_maybe); |
| 4111 | return gen_const_val(g, const_val->data.x_maybe, ""); |
| 4112 | 4112 | } else { |
| 4113 | 4113 | return LLVMConstNull(child_type->type_ref); |
| 4114 | 4114 | } |
| ... | ... | @@ -4117,7 +4117,7 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val) { |
| 4117 | 4117 | LLVMValueRef maybe_val; |
| 4118 | 4118 | bool make_unnamed_struct; |
| 4119 | 4119 | if (const_val->data.x_maybe) { |
| 4120 | | child_val = gen_const_val(g, const_val->data.x_maybe); |
| 4120 | child_val = gen_const_val(g, const_val->data.x_maybe, ""); |
| 4121 | 4121 | maybe_val = LLVMConstAllOnes(LLVMInt1Type()); |
| 4122 | 4122 | |
| 4123 | 4123 | make_unnamed_struct = is_llvm_value_unnamed_type(const_val->type, child_val); |
| ... | ... | @@ -4161,7 +4161,7 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val) { |
| 4161 | 4161 | |
| 4162 | 4162 | if (src_field_index + 1 == src_field_index_end) { |
| 4163 | 4163 | ConstExprValue *field_val = &const_val->data.x_struct.fields[src_field_index]; |
| 4164 | | LLVMValueRef val = gen_const_val(g, field_val); |
| 4164 | LLVMValueRef val = gen_const_val(g, field_val, ""); |
| 4165 | 4165 | fields[type_struct_field->gen_index] = val; |
| 4166 | 4166 | make_unnamed_struct = make_unnamed_struct || is_llvm_value_unnamed_type(field_val->type, val); |
| 4167 | 4167 | } else { |
| ... | ... | @@ -4201,7 +4201,7 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val) { |
| 4201 | 4201 | continue; |
| 4202 | 4202 | } |
| 4203 | 4203 | ConstExprValue *field_val = &const_val->data.x_struct.fields[i]; |
| 4204 | | LLVMValueRef val = gen_const_val(g, field_val); |
| 4204 | LLVMValueRef val = gen_const_val(g, field_val, ""); |
| 4205 | 4205 | fields[type_struct_field->gen_index] = val; |
| 4206 | 4206 | make_unnamed_struct = make_unnamed_struct || is_llvm_value_unnamed_type(field_val->type, val); |
| 4207 | 4207 | } |
| ... | ... | @@ -4225,7 +4225,7 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val) { |
| 4225 | 4225 | bool make_unnamed_struct = false; |
| 4226 | 4226 | for (uint64_t i = 0; i < len; i += 1) { |
| 4227 | 4227 | ConstExprValue *elem_value = &const_val->data.x_array.s_none.elements[i]; |
| 4228 | | LLVMValueRef val = gen_const_val(g, elem_value); |
| 4228 | LLVMValueRef val = gen_const_val(g, elem_value, ""); |
| 4229 | 4229 | values[i] = val; |
| 4230 | 4230 | make_unnamed_struct = make_unnamed_struct || is_llvm_value_unnamed_type(elem_value->type, val); |
| 4231 | 4231 | } |
| ... | ... | @@ -4260,7 +4260,7 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val) { |
| 4260 | 4260 | } else { |
| 4261 | 4261 | uint64_t field_type_bytes = LLVMStoreSizeOfType(g->target_data_ref, payload_value->type->type_ref); |
| 4262 | 4262 | uint64_t pad_bytes = type_entry->data.unionation.union_size_bytes - field_type_bytes; |
| 4263 | | LLVMValueRef correctly_typed_value = gen_const_val(g, payload_value); |
| 4263 | LLVMValueRef correctly_typed_value = gen_const_val(g, payload_value, ""); |
| 4264 | 4264 | make_unnamed_struct = is_llvm_value_unnamed_type(payload_value->type, correctly_typed_value) || |
| 4265 | 4265 | payload_value->type != type_entry->data.unionation.most_aligned_union_member; |
| 4266 | 4266 | |
| ... | ... | @@ -4305,7 +4305,7 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val) { |
| 4305 | 4305 | return fn_llvm_value(g, const_val->data.x_fn.fn_entry); |
| 4306 | 4306 | case TypeTableEntryIdPointer: |
| 4307 | 4307 | { |
| 4308 | | render_const_val_global(g, const_val, ""); |
| 4308 | render_const_val_global(g, const_val, name); |
| 4309 | 4309 | switch (const_val->data.x_ptr.special) { |
| 4310 | 4310 | case ConstPtrSpecialInvalid: |
| 4311 | 4311 | case ConstPtrSpecialDiscard: |
| ... | ... | @@ -4313,7 +4313,7 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val) { |
| 4313 | 4313 | case ConstPtrSpecialRef: |
| 4314 | 4314 | { |
| 4315 | 4315 | ConstExprValue *pointee = const_val->data.x_ptr.data.ref.pointee; |
| 4316 | | render_const_val(g, pointee); |
| 4316 | render_const_val(g, pointee, ""); |
| 4317 | 4317 | render_const_val_global(g, pointee, ""); |
| 4318 | 4318 | ConstExprValue *other_val = pointee; |
| 4319 | 4319 | const_val->global_refs->llvm_value = LLVMConstBitCast(other_val->global_refs->llvm_global, const_val->type->type_ref); |
| ... | ... | @@ -4383,7 +4383,7 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val) { |
| 4383 | 4383 | return LLVMConstInt(g->err_tag_type->type_ref, value, false); |
| 4384 | 4384 | } else if (!type_has_bits(err_set_type)) { |
| 4385 | 4385 | assert(type_has_bits(payload_type)); |
| 4386 | | return gen_const_val(g, const_val->data.x_err_union.payload); |
| 4386 | return gen_const_val(g, const_val->data.x_err_union.payload, ""); |
| 4387 | 4387 | } else { |
| 4388 | 4388 | LLVMValueRef err_tag_value; |
| 4389 | 4389 | LLVMValueRef err_payload_value; |
| ... | ... | @@ -4395,7 +4395,7 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val) { |
| 4395 | 4395 | } else { |
| 4396 | 4396 | err_tag_value = LLVMConstNull(g->err_tag_type->type_ref); |
| 4397 | 4397 | ConstExprValue *payload_val = const_val->data.x_err_union.payload; |
| 4398 | | err_payload_value = gen_const_val(g, payload_val); |
| 4398 | err_payload_value = gen_const_val(g, payload_val, ""); |
| 4399 | 4399 | make_unnamed_struct = is_llvm_value_unnamed_type(payload_val->type, err_payload_value); |
| 4400 | 4400 | } |
| 4401 | 4401 | LLVMValueRef fields[] = { |
| ... | ... | @@ -4430,11 +4430,11 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val) { |
| 4430 | 4430 | zig_unreachable(); |
| 4431 | 4431 | } |
| 4432 | 4432 | |
| 4433 | | static void render_const_val(CodeGen *g, ConstExprValue *const_val) { |
| 4433 | static void render_const_val(CodeGen *g, ConstExprValue *const_val, const char *name) { |
| 4434 | 4434 | if (!const_val->global_refs) |
| 4435 | 4435 | const_val->global_refs = allocate<ConstGlobalRefs>(1); |
| 4436 | 4436 | if (!const_val->global_refs->llvm_value) |
| 4437 | | const_val->global_refs->llvm_value = gen_const_val(g, const_val); |
| 4437 | const_val->global_refs->llvm_value = gen_const_val(g, const_val, name); |
| 4438 | 4438 | |
| 4439 | 4439 | if (const_val->global_refs->llvm_global) |
| 4440 | 4440 | LLVMSetInitializer(const_val->global_refs->llvm_global, const_val->global_refs->llvm_value); |
| ... | ... | @@ -4663,7 +4663,7 @@ static void do_code_gen(CodeGen *g) { |
| 4663 | 4663 | coerced_value.special = ConstValSpecialStatic; |
| 4664 | 4664 | coerced_value.type = var_type; |
| 4665 | 4665 | coerced_value.data.x_f128 = bigfloat_to_f128(&const_val->data.x_bigfloat); |
| 4666 | | LLVMValueRef init_val = gen_const_val(g, &coerced_value); |
| 4666 | LLVMValueRef init_val = gen_const_val(g, &coerced_value, ""); |
| 4667 | 4667 | gen_global_var(g, var, init_val, var_type); |
| 4668 | 4668 | continue; |
| 4669 | 4669 | } |
| ... | ... | @@ -4697,8 +4697,9 @@ static void do_code_gen(CodeGen *g) { |
| 4697 | 4697 | LLVMSetAlignment(global_value, var->align_bytes); |
| 4698 | 4698 | } else { |
| 4699 | 4699 | bool exported = (var->linkage == VarLinkageExport); |
| 4700 | | render_const_val(g, var->value); |
| 4701 | | render_const_val_global(g, var->value, buf_ptr(get_mangled_name(g, &var->name, exported))); |
| 4700 | const char *mangled_name = buf_ptr(get_mangled_name(g, &var->name, exported)); |
| 4701 | render_const_val(g, var->value, mangled_name); |
| 4702 | render_const_val_global(g, var->value, mangled_name); |
| 4702 | 4703 | global_value = var->value->global_refs->llvm_global; |
| 4703 | 4704 | |
| 4704 | 4705 | if (exported) { |