| author | |
| committer | |
| log | c0c9d11d8c509fdd1e60492abb1215d9860c3d39 |
| tree | 0fa83a1731000ea6d0c760817ccc5434652d713c |
| parent | f839d34baa8213048a1f073a38bf9b54af74711d |
| signature |
- for one-possible-value types, ir_analyze_struct_field_ptr()
no longer hardcodes const/volatile
- when slicing arrays, ir_analyze_instruction_slice()
no longer consults ConstValSpecialStatic
closes #54743 files changed, 62 insertions(+), 4 deletions(-)
src/ir.cpp+4-4| ... | ... | @@ -21924,7 +21924,9 @@ static IrInstGen *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInst* source_ins |
| 21924 | 21924 | case OnePossibleValueYes: { |
| 21925 | 21925 | IrInstGen *elem = ir_const_move(ira, source_instr, |
| 21926 | 21926 | get_the_one_possible_value(ira->codegen, field_type)); |
| 21927 | return ir_get_ref(ira, source_instr, elem, false, false); | |
| 21927 | return ir_get_ref(ira, source_instr, elem, | |
| 21928 | struct_ptr->value->type->data.pointer.is_const, | |
| 21929 | struct_ptr->value->type->data.pointer.is_volatile); | |
| 21928 | 21930 | } |
| 21929 | 21931 | case OnePossibleValueNo: |
| 21930 | 21932 | break; |
| ... | ... | @@ -27097,10 +27099,8 @@ static IrInstGen *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstSrcSlice *i |
| 27097 | 27099 | |
| 27098 | 27100 | if (array_type->id == ZigTypeIdArray) { |
| 27099 | 27101 | elem_type = array_type->data.array.child_type; |
| 27100 | bool is_comptime_const = ptr_ptr->value->special == ConstValSpecialStatic && | |
| 27101 | ptr_ptr->value->data.x_ptr.mut == ConstPtrMutComptimeConst; | |
| 27102 | 27102 | non_sentinel_slice_ptr_type = get_pointer_to_type_extra(ira->codegen, elem_type, |
| 27103 | ptr_ptr_type->data.pointer.is_const || is_comptime_const, | |
| 27103 | ptr_ptr_type->data.pointer.is_const, | |
| 27104 | 27104 | ptr_ptr_type->data.pointer.is_volatile, |
| 27105 | 27105 | PtrLenUnknown, |
| 27106 | 27106 | ptr_ptr_type->data.pointer.explicit_alignment, 0, 0, false); |
test/stage1/behavior.zig+1| ... | ... | @@ -50,6 +50,7 @@ comptime { |
| 50 | 50 | _ = @import("behavior/bugs/4769_b.zig"); |
| 51 | 51 | _ = @import("behavior/bugs/4769_c.zig"); |
| 52 | 52 | _ = @import("behavior/bugs/4954.zig"); |
| 53 | _ = @import("behavior/bugs/5474.zig"); | |
| 53 | 54 | _ = @import("behavior/bugs/5487.zig"); |
| 54 | 55 | _ = @import("behavior/bugs/394.zig"); |
| 55 | 56 | _ = @import("behavior/bugs/421.zig"); |
test/stage1/behavior/bugs/5474.zig created+57| ... | ... | @@ -0,0 +1,57 @@ |
| 1 | const std = @import("std"); | |
| 2 | ||
| 3 | // baseline (control) struct with array of scalar | |
| 4 | const Box0 = struct { | |
| 5 | items: [4]Item, | |
| 6 | ||
| 7 | const Item = struct { | |
| 8 | num: u32, | |
| 9 | }; | |
| 10 | }; | |
| 11 | ||
| 12 | // struct with array of empty struct | |
| 13 | const Box1 = struct { | |
| 14 | items: [4]Item, | |
| 15 | ||
| 16 | const Item = struct {}; | |
| 17 | }; | |
| 18 | ||
| 19 | // struct with array of zero-size struct | |
| 20 | const Box2 = struct { | |
| 21 | items: [4]Item, | |
| 22 | ||
| 23 | const Item = struct { | |
| 24 | nothing: void, | |
| 25 | }; | |
| 26 | }; | |
| 27 | ||
| 28 | fn doTest() void { | |
| 29 | // var | |
| 30 | { | |
| 31 | var box0: Box0 = .{ .items = undefined }; | |
| 32 | std.testing.expect(@typeInfo(@TypeOf(box0.items[0..])).Pointer.is_const == false); | |
| 33 | ||
| 34 | var box1: Box1 = .{ .items = undefined }; | |
| 35 | std.testing.expect(@typeInfo(@TypeOf(box1.items[0..])).Pointer.is_const == false); | |
| 36 | ||
| 37 | var box2: Box2 = .{ .items = undefined }; | |
| 38 | std.testing.expect(@typeInfo(@TypeOf(box2.items[0..])).Pointer.is_const == false); | |
| 39 | } | |
| 40 | ||
| 41 | // const | |
| 42 | { | |
| 43 | const box0: Box0 = .{ .items = undefined }; | |
| 44 | std.testing.expect(@typeInfo(@TypeOf(box0.items[0..])).Pointer.is_const == true); | |
| 45 | ||
| 46 | const box1: Box1 = .{ .items = undefined }; | |
| 47 | std.testing.expect(@typeInfo(@TypeOf(box1.items[0..])).Pointer.is_const == true); | |
| 48 | ||
| 49 | const box2: Box2 = .{ .items = undefined }; | |
| 50 | std.testing.expect(@typeInfo(@TypeOf(box2.items[0..])).Pointer.is_const == true); | |
| 51 | } | |
| 52 | } | |
| 53 | ||
| 54 | test "pointer-to-array constness for zero-size elements" { | |
| 55 | doTest(); | |
| 56 | comptime doTest(); | |
| 57 | } |