mirror of
https://github.com/ziglang/zig.git
synced 2026-02-14 13:30:45 +00:00
Fix generation of comptime slices
By erasing the global_refs field we'd trip any codepath using const_values_equal_ptr to figure if two slices were different.
This commit is contained in:
parent
1ed38a682e
commit
49838a9f3e
@ -17329,7 +17329,9 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira,
|
||||
if (const_val.special == ConstValSpecialStatic) {
|
||||
IrInstruction *result = ir_const(ira, &instruction->base, nullptr);
|
||||
ConstExprValue *out_val = &result->value;
|
||||
copy_const_val(out_val, &const_val, true);
|
||||
// Make sure to pass same_global_refs=false here in order not to
|
||||
// zero the global_refs field for `result` (#1608)
|
||||
copy_const_val(out_val, &const_val, false);
|
||||
result->value.type = fixed_size_array_type;
|
||||
for (size_t i = 0; i < elem_count; i += 1) {
|
||||
ConstExprValue *elem_val = &out_val->data.x_array.data.s_none.elements[i];
|
||||
|
||||
@ -47,3 +47,16 @@ test "C pointer" {
|
||||
var slice = buf[0..len];
|
||||
expectEqualSlices(u8, "kjdhfkjdhf", slice);
|
||||
}
|
||||
|
||||
fn sliceSum(comptime q: []const u8) i32 {
|
||||
comptime var result = 0;
|
||||
inline for (q) |item| {
|
||||
result += item;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
test "comptime slices are disambiguated" {
|
||||
expect(sliceSum([]u8{ 1, 2 }) == 3);
|
||||
expect(sliceSum([]u8{ 3, 4 }) == 7);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user