mirror of
https://github.com/ziglang/zig.git
synced 2026-02-12 20:37:54 +00:00
parent
cc0f660ad2
commit
44ae891bd7
@ -15821,9 +15821,13 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio
|
||||
TypeTableEntry *return_type;
|
||||
|
||||
if (array_type->id == TypeTableEntryIdArray) {
|
||||
uint32_t byte_alignment = ptr_type->data.pointer.alignment;
|
||||
if (array_type->data.array.len == 0 && byte_alignment == 0) {
|
||||
byte_alignment = get_abi_alignment(ira->codegen, array_type->data.array.child_type);
|
||||
}
|
||||
TypeTableEntry *slice_ptr_type = get_pointer_to_type_extra(ira->codegen, array_type->data.array.child_type,
|
||||
ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile,
|
||||
ptr_type->data.pointer.alignment, 0, 0);
|
||||
byte_alignment, 0, 0);
|
||||
return_type = get_slice_type(ira->codegen, slice_ptr_type);
|
||||
} else if (array_type->id == TypeTableEntryIdPointer) {
|
||||
TypeTableEntry *slice_ptr_type = get_pointer_to_type_extra(ira->codegen, array_type->data.pointer.child_type,
|
||||
|
||||
@ -650,3 +650,13 @@ test "packed struct, enum, union parameters in extern function" {
|
||||
|
||||
export fn testPackedStuff(a: &const PackedStruct, b: &const PackedUnion, c: PackedEnum) void {
|
||||
}
|
||||
|
||||
|
||||
test "slicing zero length array" {
|
||||
const s1 = ""[0..];
|
||||
const s2 = ([]u32{})[0..];
|
||||
assert(s1.len == 0);
|
||||
assert(s2.len == 0);
|
||||
assert(mem.eql(u8, s1, ""));
|
||||
assert(mem.eql(u32, s2, []u32{}));
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user