| author | |
| committer | |
| log | 49838a9f3eee0df33d2994b92875314363b32dfc |
| tree | 9d88deed4d89a5b528d8f6500910ca98d322566b |
| parent | 1ed38a682ec6cabcd72472b6988b27b10714216a |
| signature |
By erasing the global_refs field we'd trip any codepath using
const_values_equal_ptr to figure if two slices were different.2 files changed, 16 insertions(+), 1 deletions(-)
src/ir.cpp+3-1| ... | ... | @@ -17329,7 +17329,9 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira, |
| 17329 | 17329 | if (const_val.special == ConstValSpecialStatic) { |
| 17330 | 17330 | IrInstruction *result = ir_const(ira, &instruction->base, nullptr); |
| 17331 | 17331 | ConstExprValue *out_val = &result->value; |
| 17332 | copy_const_val(out_val, &const_val, true); | |
| 17332 | // Make sure to pass same_global_refs=false here in order not to | |
| 17333 | // zero the global_refs field for `result` (#1608) | |
| 17334 | copy_const_val(out_val, &const_val, false); | |
| 17333 | 17335 | result->value.type = fixed_size_array_type; |
| 17334 | 17336 | for (size_t i = 0; i < elem_count; i += 1) { |
| 17335 | 17337 | ConstExprValue *elem_val = &out_val->data.x_array.data.s_none.elements[i]; |
test/stage1/behavior/slice.zig+13| ... | ... | @@ -47,3 +47,16 @@ test "C pointer" { |
| 47 | 47 | var slice = buf[0..len]; |
| 48 | 48 | expectEqualSlices(u8, "kjdhfkjdhf", slice); |
| 49 | 49 | } |
| 50 | ||
| 51 | fn sliceSum(comptime q: []const u8) i32 { | |
| 52 | comptime var result = 0; | |
| 53 | inline for (q) |item| { | |
| 54 | result += item; | |
| 55 | } | |
| 56 | return result; | |
| 57 | } | |
| 58 | ||
| 59 | test "comptime slices are disambiguated" { | |
| 60 | expect(sliceSum([]u8{ 1, 2 }) == 3); | |
| 61 | expect(sliceSum([]u8{ 3, 4 }) == 7); | |
| 62 | } |