authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-12-01 00:29:16-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-12-01 00:29:16-05:00
logb5df18c8fd725a2993c520ddc8777ecad71e3d11
tree7036027c6652261cfeafce4819c809f1808e58dc
parent951dc451d6d49fca499e9a722a3f543d6e8bf7c1
signaturelock-open Commit is signed but in an unrecognized format.

inline ConstGlobalRefs into ZigValue

Having ConstGlobalRefs be a pointer in ZigValue was a hack that caused plenty of bugs. It was used to work around difficulties in type coercing array values into slices. However, after #3787 is merged, array values no longer type coerce into slices, and so this provided an opportunity to clean up the code. This has the nice effect of reducing stage1 peak RAM usage during the std lib tests from 3.443 GiB to 3.405 GiB (saving 39 MiB). There is one behavior test failing in this branch, which I plan to debug after merging #3787.

6 files changed, 103 insertions(+), 164 deletions(-)

src/all_types.hpp+3-7
......@@ -313,12 +313,6 @@ struct RuntimeHintSlice {
313313 uint64_t len;
314314};
315315
316struct ConstGlobalRefs {
317 LLVMValueRef llvm_value;
318 LLVMValueRef llvm_global;
319 uint32_t align;
320};
321
322316enum LazyValueId {
323317 LazyValueIdInvalid,
324318 LazyValueIdAlignOf,
......@@ -409,8 +403,10 @@ struct LazyValueErrUnionType {
409403struct ZigValue {
410404 ZigType *type;
411405 ConstValSpecial special;
406 uint32_t llvm_align;
412407 ConstParent parent;
413 ConstGlobalRefs *global_refs;
408 LLVMValueRef llvm_value;
409 LLVMValueRef llvm_global;
414410
415411 union {
416412 // populated if special == ConstValSpecialStatic
src/analyze.cpp+6-23
......@@ -5908,12 +5908,7 @@ ZigValue *create_const_arg_tuple(CodeGen *g, size_t arg_index_start, size_t arg_
59085908
59095909
59105910ZigValue *create_const_vals(size_t count) {
5911 ConstGlobalRefs *global_refs = allocate<ConstGlobalRefs>(count, "ConstGlobalRefs");
5912 ZigValue *vals = allocate<ZigValue>(count, "ZigValue");
5913 for (size_t i = 0; i < count; i += 1) {
5914 vals[i].global_refs = &global_refs[i];
5915 }
5916 return vals;
5911 return allocate<ZigValue>(count, "ZigValue");
59175912}
59185913
59195914ZigValue **alloc_const_vals_ptrs(size_t count) {
......@@ -6480,20 +6475,14 @@ bool const_values_equal_ptr(ZigValue *a, ZigValue *b) {
64806475 return false;
64816476 return true;
64826477 case ConstPtrSpecialBaseArray:
6483 if (a->data.x_ptr.data.base_array.array_val != b->data.x_ptr.data.base_array.array_val &&
6484 a->data.x_ptr.data.base_array.array_val->global_refs !=
6485 b->data.x_ptr.data.base_array.array_val->global_refs)
6486 {
6478 if (a->data.x_ptr.data.base_array.array_val != b->data.x_ptr.data.base_array.array_val) {
64876479 return false;
64886480 }
64896481 if (a->data.x_ptr.data.base_array.elem_index != b->data.x_ptr.data.base_array.elem_index)
64906482 return false;
64916483 return true;
64926484 case ConstPtrSpecialBaseStruct:
6493 if (a->data.x_ptr.data.base_struct.struct_val != b->data.x_ptr.data.base_struct.struct_val &&
6494 a->data.x_ptr.data.base_struct.struct_val->global_refs !=
6495 b->data.x_ptr.data.base_struct.struct_val->global_refs)
6496 {
6485 if (a->data.x_ptr.data.base_struct.struct_val != b->data.x_ptr.data.base_struct.struct_val) {
64976486 return false;
64986487 }
64996488 if (a->data.x_ptr.data.base_struct.field_index != b->data.x_ptr.data.base_struct.field_index)
......@@ -6501,27 +6490,21 @@ bool const_values_equal_ptr(ZigValue *a, ZigValue *b) {
65016490 return true;
65026491 case ConstPtrSpecialBaseErrorUnionCode:
65036492 if (a->data.x_ptr.data.base_err_union_code.err_union_val !=
6504 b->data.x_ptr.data.base_err_union_code.err_union_val &&
6505 a->data.x_ptr.data.base_err_union_code.err_union_val->global_refs !=
6506 b->data.x_ptr.data.base_err_union_code.err_union_val->global_refs)
6493 b->data.x_ptr.data.base_err_union_code.err_union_val)
65076494 {
65086495 return false;
65096496 }
65106497 return true;
65116498 case ConstPtrSpecialBaseErrorUnionPayload:
65126499 if (a->data.x_ptr.data.base_err_union_payload.err_union_val !=
6513 b->data.x_ptr.data.base_err_union_payload.err_union_val &&
6514 a->data.x_ptr.data.base_err_union_payload.err_union_val->global_refs !=
6515 b->data.x_ptr.data.base_err_union_payload.err_union_val->global_refs)
6500 b->data.x_ptr.data.base_err_union_payload.err_union_val)
65166501 {
65176502 return false;
65186503 }
65196504 return true;
65206505 case ConstPtrSpecialBaseOptionalPayload:
65216506 if (a->data.x_ptr.data.base_optional_payload.optional_val !=
6522 b->data.x_ptr.data.base_optional_payload.optional_val &&
6523 a->data.x_ptr.data.base_optional_payload.optional_val->global_refs !=
6524 b->data.x_ptr.data.base_optional_payload.optional_val->global_refs)
6507 b->data.x_ptr.data.base_optional_payload.optional_val)
65256508 {
65266509 return false;
65276510 }
src/codegen.cpp+42-68
......@@ -946,7 +946,7 @@ static Buf *panic_msg_buf(PanicMsgId msg_id) {
946946
947947static LLVMValueRef get_panic_msg_ptr_val(CodeGen *g, PanicMsgId msg_id) {
948948 ZigValue *val = &g->panic_msg_vals[msg_id];
949 if (!val->global_refs->llvm_global) {
949 if (!val->llvm_global) {
950950
951951 Buf *buf_msg = panic_msg_buf(msg_id);
952952 ZigValue *array_val = create_const_str_lit(g, buf_msg)->data.x_ptr.data.ref.pointee;
......@@ -955,13 +955,13 @@ static LLVMValueRef get_panic_msg_ptr_val(CodeGen *g, PanicMsgId msg_id) {
955955 render_const_val(g, val, "");
956956 render_const_val_global(g, val, "");
957957
958 assert(val->global_refs->llvm_global);
958 assert(val->llvm_global);
959959 }
960960
961961 ZigType *u8_ptr_type = get_pointer_to_type_extra(g, g->builtin_types.entry_u8, true, false,
962962 PtrLenUnknown, get_abi_alignment(g, g->builtin_types.entry_u8), 0, 0, false);
963963 ZigType *str_type = get_slice_type(g, u8_ptr_type);
964 return LLVMConstBitCast(val->global_refs->llvm_global, LLVMPointerType(get_llvm_type(g, str_type), 0));
964 return LLVMConstBitCast(val->llvm_global, LLVMPointerType(get_llvm_type(g, str_type), 0));
965965}
966966
967967static ZigType *ptr_to_stack_trace_type(CodeGen *g) {
......@@ -1727,9 +1727,9 @@ static LLVMValueRef ir_llvm_value(CodeGen *g, IrInstruction *instruction) {
17271727 if (handle_is_ptr(instruction->value->type)) {
17281728 render_const_val_global(g, instruction->value, "");
17291729 ZigType *ptr_type = get_pointer_to_type(g, instruction->value->type, true);
1730 instruction->llvm_value = LLVMBuildBitCast(g->builder, instruction->value->global_refs->llvm_global, get_llvm_type(g, ptr_type), "");
1730 instruction->llvm_value = LLVMBuildBitCast(g->builder, instruction->value->llvm_global, get_llvm_type(g, ptr_type), "");
17311731 } else {
1732 instruction->llvm_value = LLVMBuildBitCast(g->builder, instruction->value->global_refs->llvm_value,
1732 instruction->llvm_value = LLVMBuildBitCast(g->builder, instruction->value->llvm_value,
17331733 get_llvm_type(g, instruction->value->type), "");
17341734 }
17351735 assert(instruction->llvm_value);
......@@ -6374,7 +6374,7 @@ static LLVMValueRef gen_parent_ptr(CodeGen *g, ZigValue *val, ConstParent *paren
63746374 case ConstParentIdNone:
63756375 render_const_val(g, val, "");
63766376 render_const_val_global(g, val, "");
6377 return val->global_refs->llvm_global;
6377 return val->llvm_global;
63786378 case ConstParentIdStruct:
63796379 return gen_const_ptr_struct_recursive(g, parent->data.p_struct.struct_val,
63806380 parent->data.p_struct.field_index);
......@@ -6392,7 +6392,7 @@ static LLVMValueRef gen_parent_ptr(CodeGen *g, ZigValue *val, ConstParent *paren
63926392 case ConstParentIdScalar:
63936393 render_const_val(g, parent->data.p_scalar.scalar_val, "");
63946394 render_const_val_global(g, parent->data.p_scalar.scalar_val, "");
6395 return parent->data.p_scalar.scalar_val->global_refs->llvm_global;
6395 return parent->data.p_scalar.scalar_val->llvm_global;
63966396 }
63976397 zig_unreachable();
63986398}
......@@ -6623,17 +6623,15 @@ static LLVMValueRef gen_const_val_ptr(CodeGen *g, ZigValue *const_val, const cha
66236623 zig_unreachable();
66246624 case ConstPtrSpecialRef:
66256625 {
6626 assert(const_val->global_refs != nullptr);
66276626 ZigValue *pointee = const_val->data.x_ptr.data.ref.pointee;
66286627 render_const_val(g, pointee, "");
66296628 render_const_val_global(g, pointee, "");
6630 const_val->global_refs->llvm_value = LLVMConstBitCast(pointee->global_refs->llvm_global,
6629 const_val->llvm_value = LLVMConstBitCast(pointee->llvm_global,
66316630 get_llvm_type(g, const_val->type));
6632 return const_val->global_refs->llvm_value;
6631 return const_val->llvm_value;
66336632 }
66346633 case ConstPtrSpecialBaseArray:
66356634 {
6636 assert(const_val->global_refs != nullptr);
66376635 ZigValue *array_const_val = const_val->data.x_ptr.data.base_array.array_val;
66386636 assert(array_const_val->type->id == ZigTypeIdArray);
66396637 if (!type_has_bits(array_const_val->type)) {
......@@ -6641,102 +6639,97 @@ static LLVMValueRef gen_const_val_ptr(CodeGen *g, ZigValue *const_val, const cha
66416639 ZigValue *pointee = array_const_val->type->data.array.sentinel;
66426640 render_const_val(g, pointee, "");
66436641 render_const_val_global(g, pointee, "");
6644 const_val->global_refs->llvm_value = LLVMConstBitCast(pointee->global_refs->llvm_global,
6642 const_val->llvm_value = LLVMConstBitCast(pointee->llvm_global,
66456643 get_llvm_type(g, const_val->type));
6646 return const_val->global_refs->llvm_value;
6644 return const_val->llvm_value;
66476645 } else {
66486646 // make this a null pointer
66496647 ZigType *usize = g->builtin_types.entry_usize;
6650 const_val->global_refs->llvm_value = LLVMConstIntToPtr(LLVMConstNull(usize->llvm_type),
6648 const_val->llvm_value = LLVMConstIntToPtr(LLVMConstNull(usize->llvm_type),
66516649 get_llvm_type(g, const_val->type));
6652 return const_val->global_refs->llvm_value;
6650 return const_val->llvm_value;
66536651 }
66546652 }
66556653 size_t elem_index = const_val->data.x_ptr.data.base_array.elem_index;
66566654 LLVMValueRef uncasted_ptr_val = gen_const_ptr_array_recursive(g, array_const_val, elem_index);
66576655 LLVMValueRef ptr_val = LLVMConstBitCast(uncasted_ptr_val, get_llvm_type(g, const_val->type));
6658 const_val->global_refs->llvm_value = ptr_val;
6656 const_val->llvm_value = ptr_val;
66596657 return ptr_val;
66606658 }
66616659 case ConstPtrSpecialBaseStruct:
66626660 {
6663 assert(const_val->global_refs != nullptr);
66646661 ZigValue *struct_const_val = const_val->data.x_ptr.data.base_struct.struct_val;
66656662 assert(struct_const_val->type->id == ZigTypeIdStruct);
66666663 if (!type_has_bits(struct_const_val->type)) {
66676664 // make this a null pointer
66686665 ZigType *usize = g->builtin_types.entry_usize;
6669 const_val->global_refs->llvm_value = LLVMConstIntToPtr(LLVMConstNull(usize->llvm_type),
6666 const_val->llvm_value = LLVMConstIntToPtr(LLVMConstNull(usize->llvm_type),
66706667 get_llvm_type(g, const_val->type));
6671 return const_val->global_refs->llvm_value;
6668 return const_val->llvm_value;
66726669 }
66736670 size_t src_field_index = const_val->data.x_ptr.data.base_struct.field_index;
66746671 size_t gen_field_index = struct_const_val->type->data.structure.fields[src_field_index]->gen_index;
66756672 LLVMValueRef uncasted_ptr_val = gen_const_ptr_struct_recursive(g, struct_const_val,
66766673 gen_field_index);
66776674 LLVMValueRef ptr_val = LLVMConstBitCast(uncasted_ptr_val, get_llvm_type(g, const_val->type));
6678 const_val->global_refs->llvm_value = ptr_val;
6675 const_val->llvm_value = ptr_val;
66796676 return ptr_val;
66806677 }
66816678 case ConstPtrSpecialBaseErrorUnionCode:
66826679 {
6683 assert(const_val->global_refs != nullptr);
66846680 ZigValue *err_union_const_val = const_val->data.x_ptr.data.base_err_union_code.err_union_val;
66856681 assert(err_union_const_val->type->id == ZigTypeIdErrorUnion);
66866682 if (!type_has_bits(err_union_const_val->type)) {
66876683 // make this a null pointer
66886684 ZigType *usize = g->builtin_types.entry_usize;
6689 const_val->global_refs->llvm_value = LLVMConstIntToPtr(LLVMConstNull(usize->llvm_type),
6685 const_val->llvm_value = LLVMConstIntToPtr(LLVMConstNull(usize->llvm_type),
66906686 get_llvm_type(g, const_val->type));
6691 return const_val->global_refs->llvm_value;
6687 return const_val->llvm_value;
66926688 }
66936689 LLVMValueRef uncasted_ptr_val = gen_const_ptr_err_union_code_recursive(g, err_union_const_val);
66946690 LLVMValueRef ptr_val = LLVMConstBitCast(uncasted_ptr_val, get_llvm_type(g, const_val->type));
6695 const_val->global_refs->llvm_value = ptr_val;
6691 const_val->llvm_value = ptr_val;
66966692 return ptr_val;
66976693 }
66986694 case ConstPtrSpecialBaseErrorUnionPayload:
66996695 {
6700 assert(const_val->global_refs != nullptr);
67016696 ZigValue *err_union_const_val = const_val->data.x_ptr.data.base_err_union_payload.err_union_val;
67026697 assert(err_union_const_val->type->id == ZigTypeIdErrorUnion);
67036698 if (!type_has_bits(err_union_const_val->type)) {
67046699 // make this a null pointer
67056700 ZigType *usize = g->builtin_types.entry_usize;
6706 const_val->global_refs->llvm_value = LLVMConstIntToPtr(LLVMConstNull(usize->llvm_type),
6701 const_val->llvm_value = LLVMConstIntToPtr(LLVMConstNull(usize->llvm_type),
67076702 get_llvm_type(g, const_val->type));
6708 return const_val->global_refs->llvm_value;
6703 return const_val->llvm_value;
67096704 }
67106705 LLVMValueRef uncasted_ptr_val = gen_const_ptr_err_union_payload_recursive(g, err_union_const_val);
67116706 LLVMValueRef ptr_val = LLVMConstBitCast(uncasted_ptr_val, get_llvm_type(g, const_val->type));
6712 const_val->global_refs->llvm_value = ptr_val;
6707 const_val->llvm_value = ptr_val;
67136708 return ptr_val;
67146709 }
67156710 case ConstPtrSpecialBaseOptionalPayload:
67166711 {
6717 assert(const_val->global_refs != nullptr);
67186712 ZigValue *optional_const_val = const_val->data.x_ptr.data.base_optional_payload.optional_val;
67196713 assert(optional_const_val->type->id == ZigTypeIdOptional);
67206714 if (!type_has_bits(optional_const_val->type)) {
67216715 // make this a null pointer
67226716 ZigType *usize = g->builtin_types.entry_usize;
6723 const_val->global_refs->llvm_value = LLVMConstIntToPtr(LLVMConstNull(usize->llvm_type),
6717 const_val->llvm_value = LLVMConstIntToPtr(LLVMConstNull(usize->llvm_type),
67246718 get_llvm_type(g, const_val->type));
6725 return const_val->global_refs->llvm_value;
6719 return const_val->llvm_value;
67266720 }
67276721 LLVMValueRef uncasted_ptr_val = gen_const_ptr_optional_payload_recursive(g, optional_const_val);
67286722 LLVMValueRef ptr_val = LLVMConstBitCast(uncasted_ptr_val, get_llvm_type(g, const_val->type));
6729 const_val->global_refs->llvm_value = ptr_val;
6723 const_val->llvm_value = ptr_val;
67306724 return ptr_val;
67316725 }
67326726 case ConstPtrSpecialHardCodedAddr:
67336727 {
6734 assert(const_val->global_refs != nullptr);
67356728 uint64_t addr_value = const_val->data.x_ptr.data.hard_coded_addr.addr;
67366729 ZigType *usize = g->builtin_types.entry_usize;
6737 const_val->global_refs->llvm_value = LLVMConstIntToPtr(
6730 const_val->llvm_value = LLVMConstIntToPtr(
67386731 LLVMConstInt(usize->llvm_type, addr_value, false), get_llvm_type(g, const_val->type));
6739 return const_val->global_refs->llvm_value;
6732 return const_val->llvm_value;
67406733 }
67416734 case ConstPtrSpecialFunction:
67426735 return LLVMConstBitCast(fn_llvm_value(g, const_val->data.x_ptr.data.fn.fn_entry),
......@@ -7175,34 +7168,29 @@ check: switch (const_val->special) {
71757168}
71767169
71777170static void render_const_val(CodeGen *g, ZigValue *const_val, const char *name) {
7178 if (!const_val->global_refs)
7179 const_val->global_refs = allocate<ConstGlobalRefs>(1);
7180 if (!const_val->global_refs->llvm_value)
7181 const_val->global_refs->llvm_value = gen_const_val(g, const_val, name);
7171 if (!const_val->llvm_value)
7172 const_val->llvm_value = gen_const_val(g, const_val, name);
71827173
7183 if (const_val->global_refs->llvm_global)
7184 LLVMSetInitializer(const_val->global_refs->llvm_global, const_val->global_refs->llvm_value);
7174 if (const_val->llvm_global)
7175 LLVMSetInitializer(const_val->llvm_global, const_val->llvm_value);
71857176}
71867177
71877178static void render_const_val_global(CodeGen *g, ZigValue *const_val, const char *name) {
7188 if (!const_val->global_refs)
7189 const_val->global_refs = allocate<ConstGlobalRefs>(1);
7190
7191 if (!const_val->global_refs->llvm_global) {
7192 LLVMTypeRef type_ref = const_val->global_refs->llvm_value ?
7193 LLVMTypeOf(const_val->global_refs->llvm_value) : get_llvm_type(g, const_val->type);
7179 if (!const_val->llvm_global) {
7180 LLVMTypeRef type_ref = const_val->llvm_value ?
7181 LLVMTypeOf(const_val->llvm_value) : get_llvm_type(g, const_val->type);
71947182 LLVMValueRef global_value = LLVMAddGlobal(g->module, type_ref, name);
71957183 LLVMSetLinkage(global_value, LLVMInternalLinkage);
71967184 LLVMSetGlobalConstant(global_value, true);
71977185 LLVMSetUnnamedAddr(global_value, true);
7198 LLVMSetAlignment(global_value, (const_val->global_refs->align == 0) ?
7199 get_abi_alignment(g, const_val->type) : const_val->global_refs->align);
7186 LLVMSetAlignment(global_value, (const_val->llvm_align == 0) ?
7187 get_abi_alignment(g, const_val->type) : const_val->llvm_align);
72007188
7201 const_val->global_refs->llvm_global = global_value;
7189 const_val->llvm_global = global_value;
72027190 }
72037191
7204 if (const_val->global_refs->llvm_value)
7205 LLVMSetInitializer(const_val->global_refs->llvm_global, const_val->global_refs->llvm_value);
7192 if (const_val->llvm_value)
7193 LLVMSetInitializer(const_val->llvm_global, const_val->llvm_value);
72067194}
72077195
72087196static void generate_error_name_table(CodeGen *g) {
......@@ -7403,7 +7391,7 @@ static void do_code_gen(CodeGen *g) {
74037391 bool exported = (linkage != GlobalLinkageIdInternal);
74047392 render_const_val(g, var->const_value, symbol_name);
74057393 render_const_val_global(g, var->const_value, symbol_name);
7406 global_value = var->const_value->global_refs->llvm_global;
7394 global_value = var->const_value->llvm_global;
74077395
74087396 if (exported) {
74097397 LLVMSetLinkage(global_value, to_llvm_linkage(linkage));
......@@ -7418,7 +7406,7 @@ static void do_code_gen(CodeGen *g) {
74187406 // Here we use const_value->type because that's the type of the llvm global,
74197407 // which we const ptr cast upon use to whatever it needs to be.
74207408 if (var->gen_is_const && var->const_value->type->id != ZigTypeIdFn) {
7421 gen_global_var(g, var, var->const_value->global_refs->llvm_value, var->const_value->type);
7409 gen_global_var(g, var, var->const_value->llvm_value, var->const_value->type);
74227410 }
74237411
74247412 LLVMSetGlobalConstant(global_value, var->gen_is_const);
......@@ -8012,31 +8000,26 @@ static void define_intern_values(CodeGen *g) {
80128000 {
80138001 auto& value = g->intern.x_undefined;
80148002 value.type = g->builtin_types.entry_undef;
8015 value.global_refs = allocate<ConstGlobalRefs>(1, "ConstGlobalRefs.undefined");
80168003 value.special = ConstValSpecialStatic;
80178004 }
80188005 {
80198006 auto& value = g->intern.x_void;
80208007 value.type = g->builtin_types.entry_void;
8021 value.global_refs = allocate<ConstGlobalRefs>(1, "ConstGlobalRefs.void");
80228008 value.special = ConstValSpecialStatic;
80238009 }
80248010 {
80258011 auto& value = g->intern.x_null;
80268012 value.type = g->builtin_types.entry_null;
8027 value.global_refs = allocate<ConstGlobalRefs>(1, "ConstGlobalRefs.null");
80288013 value.special = ConstValSpecialStatic;
80298014 }
80308015 {
80318016 auto& value = g->intern.x_unreachable;
80328017 value.type = g->builtin_types.entry_unreachable;
8033 value.global_refs = allocate<ConstGlobalRefs>(1, "ConstGlobalRefs.unreachable");
80348018 value.special = ConstValSpecialStatic;
80358019 }
80368020 {
80378021 auto& value = g->intern.zero_byte;
80388022 value.type = g->builtin_types.entry_u8;
8039 value.global_refs = allocate<ConstGlobalRefs>(1, "ConstGlobalRefs.zero_byte");
80408023 value.special = ConstValSpecialStatic;
80418024 bigint_init_unsigned(&value.data.x_bigint, 0);
80428025 }
......@@ -8669,19 +8652,10 @@ static void init(CodeGen *g) {
86698652 g->invalid_instruction = &sentinel_instructions[0];
86708653 g->invalid_instruction->value = allocate<ZigValue>(1, "ZigValue");
86718654 g->invalid_instruction->value->type = g->builtin_types.entry_invalid;
8672 g->invalid_instruction->value->global_refs = allocate<ConstGlobalRefs>(1);
86738655
86748656 g->unreach_instruction = &sentinel_instructions[1];
86758657 g->unreach_instruction->value = allocate<ZigValue>(1, "ZigValue");
86768658 g->unreach_instruction->value->type = g->builtin_types.entry_unreachable;
8677 g->unreach_instruction->value->global_refs = allocate<ConstGlobalRefs>(1);
8678
8679 {
8680 ConstGlobalRefs *global_refs = allocate<ConstGlobalRefs>(PanicMsgIdCount);
8681 for (size_t i = 0; i < PanicMsgIdCount; i += 1) {
8682 g->panic_msg_vals[i].global_refs = &global_refs[i];
8683 }
8684 }
86858659
86868660 define_builtin_fns(g);
86878661 Error err;
src/ir.cpp+49-63
......@@ -219,7 +219,7 @@ static Error ir_read_const_ptr(IrAnalyze *ira, CodeGen *codegen, AstNode *source
219219static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *ptr,
220220 ZigType *dest_type, IrInstruction *dest_type_src, bool safety_check_on);
221221static ZigValue *ir_resolve_const(IrAnalyze *ira, IrInstruction *value, UndefAllowed undef_allowed);
222static void copy_const_val(ZigValue *dest, ZigValue *src, bool same_global_refs);
222static void copy_const_val(ZigValue *dest, ZigValue *src);
223223static Error resolve_ptr_align(IrAnalyze *ira, ZigType *ty, uint32_t *result_align);
224224static IrInstruction *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *target,
225225 ZigType *ptr_type);
......@@ -1165,7 +1165,6 @@ static T *ir_create_instruction(IrBuilder *irb, Scope *scope, AstNode *source_no
11651165 special_instruction->base.debug_id = exec_next_debug_id(irb->exec);
11661166 special_instruction->base.owner_bb = irb->current_basic_block;
11671167 special_instruction->base.value = allocate<ZigValue>(1, "ZigValue");
1168 special_instruction->base.value->global_refs = allocate<ConstGlobalRefs>(1, "ConstGlobalRefs");
11691168 return special_instruction;
11701169}
11711170
......@@ -8735,7 +8734,7 @@ static Error eval_comptime_ptr_reinterpret(IrAnalyze *ira, CodeGen *codegen, Ast
87358734 if ((err = ir_read_const_ptr(ira, codegen, source_node, &tmp, ptr_val)))
87368735 return err;
87378736 ZigValue *child_val = const_ptr_pointee_unchecked(codegen, ptr_val);
8738 copy_const_val(child_val, &tmp, false);
8737 copy_const_val(child_val, &tmp);
87398738 return ErrorNone;
87408739}
87418740
......@@ -11018,18 +11017,14 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
1101811017 }
1101911018}
1102011019
11021static void copy_const_val(ZigValue *dest, ZigValue *src, bool same_global_refs) {
11022 ConstGlobalRefs *global_refs = dest->global_refs;
11020static void copy_const_val(ZigValue *dest, ZigValue *src) {
1102311021 memcpy(dest, src, sizeof(ZigValue));
11024 if (!same_global_refs) {
11025 dest->global_refs = global_refs;
11026 if (src->special != ConstValSpecialStatic)
11027 return;
11028 if (dest->type->id == ZigTypeIdStruct) {
11029 dest->data.x_struct.fields = alloc_const_vals_ptrs(dest->type->data.structure.src_field_count);
11030 for (size_t i = 0; i < dest->type->data.structure.src_field_count; i += 1) {
11031 copy_const_val(dest->data.x_struct.fields[i], src->data.x_struct.fields[i], false);
11032 }
11022 if (src->special != ConstValSpecialStatic)
11023 return;
11024 if (dest->type->id == ZigTypeIdStruct) {
11025 dest->data.x_struct.fields = alloc_const_vals_ptrs(dest->type->data.structure.src_field_count);
11026 for (size_t i = 0; i < dest->type->data.structure.src_field_count; i += 1) {
11027 copy_const_val(dest->data.x_struct.fields[i], src->data.x_struct.fields[i]);
1103311028 }
1103411029 }
1103511030}
......@@ -11048,13 +11043,11 @@ static bool eval_const_expr_implicit_cast(IrAnalyze *ira, IrInstruction *source_
1104811043 case CastOpErrSet:
1104911044 case CastOpBitCast:
1105011045 zig_panic("TODO");
11051 case CastOpNoop:
11052 {
11053 bool same_global_refs = other_val->special == ConstValSpecialStatic;
11054 copy_const_val(const_val, other_val, same_global_refs);
11055 const_val->type = new_type;
11056 break;
11057 }
11046 case CastOpNoop: {
11047 copy_const_val(const_val, other_val);
11048 const_val->type = new_type;
11049 break;
11050 }
1105811051 case CastOpNumLitToConcrete:
1105911052 if (other_val->type->id == ZigTypeIdComptimeFloat) {
1106011053 assert(new_type->id == ZigTypeIdFloat);
......@@ -11775,7 +11768,7 @@ static IrInstruction *ir_analyze_optional_wrap(IrAnalyze *ira, IrInstruction *so
1177511768 source_instr->scope, source_instr->source_node);
1177611769 const_instruction->base.value->special = ConstValSpecialStatic;
1177711770 if (types_have_same_zig_comptime_repr(ira->codegen, wanted_type, payload_type)) {
11778 copy_const_val(const_instruction->base.value, val, val->data.x_ptr.mut == ConstPtrMutComptimeConst);
11771 copy_const_val(const_instruction->base.value, val);
1177911772 } else {
1178011773 const_instruction->base.value->data.x_optional = val;
1178111774 }
......@@ -12779,7 +12772,7 @@ static IrInstruction *ir_analyze_array_to_vector(IrAnalyze *ira, IrInstruction *
1277912772 if (instr_is_comptime(array)) {
1278012773 // arrays and vectors have the same ZigValue representation
1278112774 IrInstruction *result = ir_const(ira, source_instr, vector_type);
12782 copy_const_val(result->value, array->value, false);
12775 copy_const_val(result->value, array->value);
1278312776 result->value->type = vector_type;
1278412777 return result;
1278512778 }
......@@ -12792,7 +12785,7 @@ static IrInstruction *ir_analyze_vector_to_array(IrAnalyze *ira, IrInstruction *
1279212785 if (instr_is_comptime(vector)) {
1279312786 // arrays and vectors have the same ZigValue representation
1279412787 IrInstruction *result = ir_const(ira, source_instr, array_type);
12795 copy_const_val(result->value, vector->value, false);
12788 copy_const_val(result->value, vector->value);
1279612789 result->value->type = array_type;
1279712790 return result;
1279812791 }
......@@ -13080,7 +13073,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1308013073 if (wanted_type->id == ZigTypeIdComptimeInt || wanted_type->id == ZigTypeIdInt) {
1308113074 IrInstruction *result = ir_const(ira, source_instr, wanted_type);
1308213075 if (actual_type->id == ZigTypeIdComptimeInt || actual_type->id == ZigTypeIdInt) {
13083 copy_const_val(result->value, value->value, false);
13076 copy_const_val(result->value, value->value);
1308413077 result->value->type = wanted_type;
1308513078 } else {
1308613079 float_init_bigint(&result->value->data.x_bigint, value->value);
......@@ -13963,7 +13956,7 @@ static IrInstruction *ir_analyze_instruction_return(IrAnalyze *ira, IrInstructio
1396313956
1396413957static IrInstruction *ir_analyze_instruction_const(IrAnalyze *ira, IrInstructionConst *instruction) {
1396513958 IrInstruction *result = ir_const(ira, &instruction->base, nullptr);
13966 copy_const_val(result->value, instruction->base.value, true);
13959 copy_const_val(result->value, instruction->base.value);
1396713960 return result;
1396813961}
1396913962
......@@ -14502,7 +14495,7 @@ never_mind_just_calculate_it_normally:
1450214495 &op1_val->data.x_array.data.s_none.elements[i],
1450314496 &op2_val->data.x_array.data.s_none.elements[i],
1450414497 bin_op_instruction, op_id, one_possible_value);
14505 copy_const_val(&result->value->data.x_array.data.s_none.elements[i], cur_res->value, false);
14498 copy_const_val(&result->value->data.x_array.data.s_none.elements[i], cur_res->value);
1450614499 }
1450714500 return result;
1450814501 }
......@@ -15368,21 +15361,21 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i
1536815361 size_t next_index = 0;
1536915362 for (size_t i = op1_array_index; i < op1_array_end; i += 1, next_index += 1) {
1537015363 ZigValue *elem_dest_val = &out_array_val->data.x_array.data.s_none.elements[next_index];
15371 copy_const_val(elem_dest_val, &op1_array_val->data.x_array.data.s_none.elements[i], false);
15364 copy_const_val(elem_dest_val, &op1_array_val->data.x_array.data.s_none.elements[i]);
1537215365 elem_dest_val->parent.id = ConstParentIdArray;
1537315366 elem_dest_val->parent.data.p_array.array_val = out_array_val;
1537415367 elem_dest_val->parent.data.p_array.elem_index = next_index;
1537515368 }
1537615369 for (size_t i = op2_array_index; i < op2_array_end; i += 1, next_index += 1) {
1537715370 ZigValue *elem_dest_val = &out_array_val->data.x_array.data.s_none.elements[next_index];
15378 copy_const_val(elem_dest_val, &op2_array_val->data.x_array.data.s_none.elements[i], false);
15371 copy_const_val(elem_dest_val, &op2_array_val->data.x_array.data.s_none.elements[i]);
1537915372 elem_dest_val->parent.id = ConstParentIdArray;
1538015373 elem_dest_val->parent.data.p_array.array_val = out_array_val;
1538115374 elem_dest_val->parent.data.p_array.elem_index = next_index;
1538215375 }
1538315376 if (next_index < full_len) {
1538415377 ZigValue *elem_dest_val = &out_array_val->data.x_array.data.s_none.elements[next_index];
15385 copy_const_val(elem_dest_val, sentinel, false);
15378 copy_const_val(elem_dest_val, sentinel);
1538615379 elem_dest_val->parent.id = ConstParentIdArray;
1538715380 elem_dest_val->parent.data.p_array.array_val = out_array_val;
1538815381 elem_dest_val->parent.data.p_array.elem_index = next_index;
......@@ -15467,7 +15460,7 @@ static IrInstruction *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp *
1546715460 for (uint64_t x = 0; x < mult_amt; x += 1) {
1546815461 for (uint64_t y = 0; y < old_array_len; y += 1) {
1546915462 ZigValue *elem_dest_val = &out_val->data.x_array.data.s_none.elements[i];
15470 copy_const_val(elem_dest_val, &array_val->data.x_array.data.s_none.elements[y], false);
15463 copy_const_val(elem_dest_val, &array_val->data.x_array.data.s_none.elements[y]);
1547115464 elem_dest_val->parent.id = ConstParentIdArray;
1547215465 elem_dest_val->parent.data.p_array.array_val = out_val;
1547315466 elem_dest_val->parent.data.p_array.elem_index = i;
......@@ -15478,7 +15471,7 @@ static IrInstruction *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp *
1547815471
1547915472 if (array_type->data.array.sentinel != nullptr) {
1548015473 ZigValue *elem_dest_val = &out_val->data.x_array.data.s_none.elements[i];
15481 copy_const_val(elem_dest_val, array_type->data.array.sentinel, false);
15474 copy_const_val(elem_dest_val, array_type->data.array.sentinel);
1548215475 elem_dest_val->parent.id = ConstParentIdArray;
1548315476 elem_dest_val->parent.data.p_array.array_val = out_val;
1548415477 elem_dest_val->parent.data.p_array.elem_index = i;
......@@ -15628,7 +15621,7 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira,
1562815621 var->const_value = init_val;
1562915622 } else {
1563015623 var->const_value = create_const_vals(1);
15631 copy_const_val(var->const_value, init_val, false);
15624 copy_const_val(var->const_value, init_val);
1563215625 }
1563315626 }
1563415627 }
......@@ -15738,7 +15731,7 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira,
1573815731 if (instr_is_comptime(var_ptr) && var->mem_slot_index != SIZE_MAX) {
1573915732 assert(var->mem_slot_index < ira->exec_context.mem_slot_list.length);
1574015733 ZigValue *mem_slot = ira->exec_context.mem_slot_list.at(var->mem_slot_index);
15741 copy_const_val(mem_slot, init_val, !is_comptime_var || var->gen_is_const);
15734 copy_const_val(mem_slot, init_val);
1574215735
1574315736 if (is_comptime_var || (var_class_requires_const && var->gen_is_const)) {
1574415737 return ir_const_void(ira, &decl_var_instruction->base);
......@@ -16217,8 +16210,8 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
1621716210 }
1621816211 IrInstruction *alloca_gen;
1621916212 if (is_comptime && value != nullptr) {
16220 if (align > value->value->global_refs->align) {
16221 value->value->global_refs->align = align;
16213 if (align > value->value->llvm_align) {
16214 value->value->llvm_align = align;
1622216215 }
1622316216 alloca_gen = ir_get_ref(ira, result_loc->source_instruction, value, true, false);
1622416217 } else {
......@@ -16782,7 +16775,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod
1678216775 arg_val = create_const_runtime(casted_arg->value->type);
1678316776 }
1678416777 if (arg_part_of_generic_id) {
16785 copy_const_val(&generic_id->params[generic_id->param_count], arg_val, true);
16778 copy_const_val(&generic_id->params[generic_id->param_count], arg_val);
1678616779 generic_id->param_count += 1;
1678716780 }
1678816781
......@@ -16963,7 +16956,7 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source
1696316956 IrInstruction *casted_ptr;
1696416957 if (instr_is_comptime(ptr)) {
1696516958 casted_ptr = ir_const(ira, source_instr, struct_ptr_type);
16966 copy_const_val(casted_ptr->value, ptr->value, false);
16959 copy_const_val(casted_ptr->value, ptr->value);
1696716960 casted_ptr->value->type = struct_ptr_type;
1696816961 } else {
1696916962 casted_ptr = ir_build_cast(&ira->new_irb, source_instr->scope,
......@@ -17026,14 +17019,7 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source
1702617019 if (dest_val == nullptr)
1702717020 return ira->codegen->invalid_instruction;
1702817021 if (dest_val->special != ConstValSpecialRuntime) {
17029 // TODO this allows a value stored to have the original value modified and then
17030 // have that affect what should be a copy. We need some kind of advanced copy-on-write
17031 // system to make these two tests pass at the same time:
17032 // * "string literal used as comptime slice is memoized"
17033 // * "comptime modification of const struct field" - except modified to avoid
17034 // ConstPtrMutComptimeVar, thus defeating the logic below.
17035 bool same_global_refs = ptr->value->data.x_ptr.mut != ConstPtrMutComptimeVar;
17036 copy_const_val(dest_val, value->value, same_global_refs);
17022 copy_const_val(dest_val, value->value);
1703717023 if (ptr->value->data.x_ptr.mut == ConstPtrMutComptimeVar &&
1703817024 !ira->new_irb.current_basic_block->must_be_comptime_source_instr)
1703917025 {
......@@ -17308,7 +17294,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c
1730817294 }
1730917295
1731017296 IrInstruction *new_instruction = ir_const(ira, &call_instruction->base, result->type);
17311 copy_const_val(new_instruction->value, result, true);
17297 copy_const_val(new_instruction->value, result);
1731217298 new_instruction->value->type = return_type;
1731317299 return ir_finish_anal(ira, new_instruction);
1731417300 }
......@@ -17465,7 +17451,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c
1746517451 nullptr, UndefBad);
1746617452 IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(&ira->new_irb,
1746717453 impl_fn->child_scope, fn_proto_node->data.fn_proto.align_expr);
17468 copy_const_val(const_instruction->base.value, align_result, true);
17454 copy_const_val(const_instruction->base.value, align_result);
1746917455
1747017456 uint32_t align_bytes = 0;
1747117457 ir_resolve_align(ira, &const_instruction->base, nullptr, &align_bytes);
......@@ -17795,7 +17781,7 @@ static Error ir_read_const_ptr(IrAnalyze *ira, CodeGen *codegen, AstNode *source
1779517781
1779617782 if (dst_size <= src_size) {
1779717783 if (src_size == dst_size && types_have_same_zig_comptime_repr(codegen, out_val->type, pointee->type)) {
17798 copy_const_val(out_val, pointee, ptr_val->data.x_ptr.mut != ConstPtrMutComptimeVar);
17784 copy_const_val(out_val, pointee);
1779917785 return ErrorNone;
1780017786 }
1780117787 Buf buf = BUF_INIT;
......@@ -18158,7 +18144,7 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh
1815818144
1815918145 if (value->value->special != ConstValSpecialRuntime) {
1816018146 IrInstruction *result = ir_const(ira, &phi_instruction->base, nullptr);
18161 copy_const_val(result->value, value->value, true);
18147 copy_const_val(result->value, value->value);
1816218148 return result;
1816318149 } else {
1816418150 return value;
......@@ -18551,7 +18537,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
1855118537 if (index == array_len && array_type->data.array.sentinel != nullptr) {
1855218538 ZigType *elem_type = array_type->data.array.child_type;
1855318539 IrInstruction *sentinel_elem = ir_const(ira, &elem_ptr_instruction->base, elem_type);
18554 copy_const_val(sentinel_elem->value, array_type->data.array.sentinel, false);
18540 copy_const_val(sentinel_elem->value, array_type->data.array.sentinel);
1855518541 return ir_get_ref(ira, &elem_ptr_instruction->base, sentinel_elem, true, false);
1855618542 }
1855718543 if (index >= array_len) {
......@@ -19042,7 +19028,7 @@ static IrInstruction *ir_analyze_inferred_field_ptr(IrAnalyze *ira, Buf *field_n
1904219028
1904319029 if (instr_is_comptime(container_ptr)) {
1904419030 IrInstruction *result = ir_const(ira, source_instr, field_ptr_type);
19045 copy_const_val(result->value, container_ptr->value, false);
19031 copy_const_val(result->value, container_ptr->value);
1904619032 result->value->type = field_ptr_type;
1904719033 return result;
1904819034 }
......@@ -20474,7 +20460,7 @@ static IrInstruction *ir_analyze_instruction_switch_target(IrAnalyze *ira,
2047420460 case ZigTypeIdErrorSet: {
2047520461 if (pointee_val) {
2047620462 IrInstruction *result = ir_const(ira, &switch_target_instruction->base, nullptr);
20477 copy_const_val(result->value, pointee_val, true);
20463 copy_const_val(result->value, pointee_val);
2047820464 result->value->type = target_type;
2047920465 return result;
2048020466 }
......@@ -20970,7 +20956,7 @@ static IrInstruction *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruc
2097020956 return ira->codegen->invalid_instruction;
2097120957
2097220958 IrInstruction *runtime_inst = ir_const(ira, instruction, field->init_val->type);
20973 copy_const_val(runtime_inst->value, field->init_val, true);
20959 copy_const_val(runtime_inst->value, field->init_val);
2097420960
2097520961 IrInstruction *field_ptr = ir_analyze_struct_field_ptr(ira, instruction, field, result_loc,
2097620962 container_type, true);
......@@ -21228,7 +21214,7 @@ static IrInstruction *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstruct
2122821214 err->cached_error_name_val = create_const_slice(ira->codegen, array_val, 0, buf_len(&err->name), true);
2122921215 }
2123021216 IrInstruction *result = ir_const(ira, &instruction->base, nullptr);
21231 copy_const_val(result->value, err->cached_error_name_val, true);
21217 copy_const_val(result->value, err->cached_error_name_val);
2123221218 result->value->type = str_type;
2123321219 return result;
2123421220 }
......@@ -22665,7 +22651,7 @@ static IrInstruction *ir_analyze_instruction_type_name(IrAnalyze *ira, IrInstruc
2266522651 type_entry->cached_const_name_val = create_const_str_lit(ira->codegen, type_bare_name(type_entry));
2266622652 }
2266722653 IrInstruction *result = ir_const(ira, &instruction->base, nullptr);
22668 copy_const_val(result->value, type_entry->cached_const_name_val, true);
22654 copy_const_val(result->value, type_entry->cached_const_name_val);
2266922655 return result;
2267022656}
2267122657
......@@ -23365,7 +23351,7 @@ static IrInstruction *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstruct
2336523351
2336623352 ZigValue *ptr_val = result->value->data.x_struct.fields[slice_ptr_index];
2336723353 ZigValue *target_ptr_val = target_val->data.x_struct.fields[slice_ptr_index];
23368 copy_const_val(ptr_val, target_ptr_val, false);
23354 copy_const_val(ptr_val, target_ptr_val);
2336923355 ptr_val->type = dest_ptr_type;
2337023356
2337123357 ZigValue *len_val = result->value->data.x_struct.fields[slice_len_index];
......@@ -23658,7 +23644,7 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s
2365823644 ZigValue *src_elem_val = (v >= 0) ?
2365923645 &a->value->data.x_array.data.s_none.elements[v] :
2366023646 &b->value->data.x_array.data.s_none.elements[~v];
23661 copy_const_val(result_elem_val, src_elem_val, false);
23647 copy_const_val(result_elem_val, src_elem_val);
2366223648
2366323649 ir_assert(result_elem_val->special == ConstValSpecialStatic, source_instr);
2366423650 }
......@@ -23753,7 +23739,7 @@ static IrInstruction *ir_analyze_instruction_splat(IrAnalyze *ira, IrInstruction
2375323739 IrInstruction *result = ir_const(ira, &instruction->base, return_type);
2375423740 result->value->data.x_array.data.s_none.elements = create_const_vals(len_int);
2375523741 for (uint32_t i = 0; i < len_int; i += 1) {
23756 copy_const_val(&result->value->data.x_array.data.s_none.elements[i], scalar_val, false);
23742 copy_const_val(&result->value->data.x_array.data.s_none.elements[i], scalar_val);
2375723743 }
2375823744 return result;
2375923745 }
......@@ -23894,7 +23880,7 @@ static IrInstruction *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructio
2389423880 }
2389523881
2389623882 for (size_t i = start; i < end; i += 1) {
23897 copy_const_val(&dest_elements[i], byte_val, true);
23883 copy_const_val(&dest_elements[i], byte_val);
2389823884 }
2389923885
2390023886 return ir_const_void(ira, &instruction->base);
......@@ -24073,7 +24059,7 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio
2407324059 // TODO check for noalias violations - this should be generalized to work for any function
2407424060
2407524061 for (size_t i = 0; i < count; i += 1) {
24076 copy_const_val(&dest_elements[dest_start + i], &src_elements[src_start + i], true);
24062 copy_const_val(&dest_elements[dest_start + i], &src_elements[src_start + i]);
2407724063 }
2407824064
2407924065 return ir_const_void(ira, &instruction->base);
......@@ -25515,7 +25501,7 @@ static IrInstruction *ir_align_cast(IrAnalyze *ira, IrInstruction *target, uint3
2551525501 }
2551625502
2551725503 IrInstruction *result = ir_const(ira, target, result_type);
25518 copy_const_val(result->value, val, true);
25504 copy_const_val(result->value, val);
2551925505 result->value->type = result_type;
2552025506 return result;
2552125507 }
......@@ -25597,7 +25583,7 @@ static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_
2559725583 } else {
2559825584 result = ir_const(ira, source_instr, dest_type);
2559925585 }
25600 copy_const_val(result->value, val, true);
25586 copy_const_val(result->value, val);
2560125587 result->value->type = dest_type;
2560225588
2560325589 // Keep the bigger alignment, it can only help-
test/stage1/behavior/bugs/1607.zig+2-2
......@@ -10,6 +10,6 @@ fn checkAddress(s: []const u8) void {
1010}
1111
1212test "slices pointing at the same address as global array." {
13 checkAddress(a);
14 comptime checkAddress(a);
13 checkAddress(&a);
14 comptime checkAddress(&a);
1515}
test/stage1/behavior/struct.zig+1-1
......@@ -783,7 +783,7 @@ test "struct with var field" {
783783 x: var,
784784 y: var,
785785 };
786 const pt = Point {
786 const pt = Point{
787787 .x = 1,
788788 .y = 2,
789789 };