mirror of
https://github.com/ziglang/zig.git
synced 2026-02-13 04:48:20 +00:00
Sema: fix empty slice pointer value
We just checked that inst_child_ty was effectively a zero-bit type, so it is certainly not the non-zero alignment we are looking for. Closes #15085
This commit is contained in:
parent
2b80552603
commit
dd66e0addb
@ -25152,7 +25152,7 @@ fn coerceExtra(
|
||||
.ptr = if (dest_info.@"align" != 0)
|
||||
try Value.Tag.int_u64.create(sema.arena, dest_info.@"align")
|
||||
else
|
||||
try inst_child_ty.lazyAbiAlignment(target, sema.arena),
|
||||
try dest_info.pointee_type.lazyAbiAlignment(target, sema.arena),
|
||||
.len = Value.zero,
|
||||
});
|
||||
return sema.addConstant(dest_ty, slice_val);
|
||||
@ -30213,6 +30213,11 @@ fn resolveLazyValue(sema: *Sema, val: Value) CompileError!void {
|
||||
try sema.resolveLazyValue(elem_val);
|
||||
}
|
||||
},
|
||||
.slice => {
|
||||
const slice = val.castTag(.slice).?.data;
|
||||
try sema.resolveLazyValue(slice.ptr);
|
||||
return sema.resolveLazyValue(slice.len);
|
||||
},
|
||||
else => return,
|
||||
}
|
||||
}
|
||||
|
||||
@ -1069,7 +1069,7 @@ pub const DeclGen = struct {
|
||||
const extern_fn = val.castTag(.extern_fn).?.data;
|
||||
try dg.renderDeclName(writer, extern_fn.owner_decl, 0);
|
||||
},
|
||||
.int_u64, .one => {
|
||||
.int_u64, .one, .int_big_positive, .lazy_align, .lazy_size => {
|
||||
try writer.writeAll("((");
|
||||
try dg.renderType(writer, ty);
|
||||
return writer.print("){x})", .{try dg.fmtIntLiteral(Type.usize, val, .Other)});
|
||||
|
||||
@ -3397,7 +3397,7 @@ pub const DeclGen = struct {
|
||||
};
|
||||
return dg.context.constStruct(&fields, fields.len, .False);
|
||||
},
|
||||
.int_u64, .one, .int_big_positive => {
|
||||
.int_u64, .one, .int_big_positive, .lazy_align, .lazy_size => {
|
||||
const llvm_usize = try dg.lowerType(Type.usize);
|
||||
const llvm_int = llvm_usize.constInt(tv.val.toUnsignedInt(target), .False);
|
||||
return llvm_int.constIntToPtr(try dg.lowerType(tv.ty));
|
||||
|
||||
@ -723,10 +723,18 @@ test "slice with dereferenced value" {
|
||||
test "empty slice ptr is non null" {
|
||||
if (builtin.zig_backend == .stage2_aarch64 and builtin.os.tag == .macos) return error.SkipZigTest; // TODO
|
||||
|
||||
const empty_slice: []u8 = &[_]u8{};
|
||||
const p: [*]u8 = empty_slice.ptr + 0;
|
||||
const t = @ptrCast([*]i8, p);
|
||||
try expect(@ptrToInt(t) == @ptrToInt(empty_slice.ptr));
|
||||
{
|
||||
const empty_slice: []u8 = &[_]u8{};
|
||||
const p: [*]u8 = empty_slice.ptr + 0;
|
||||
const t = @ptrCast([*]i8, p);
|
||||
try expect(@ptrToInt(t) == @ptrToInt(empty_slice.ptr));
|
||||
}
|
||||
{
|
||||
const empty_slice: []u8 = &.{};
|
||||
const p: [*]u8 = empty_slice.ptr + 0;
|
||||
const t = @ptrCast([*]i8, p);
|
||||
try expect(@ptrToInt(t) == @ptrToInt(empty_slice.ptr));
|
||||
}
|
||||
}
|
||||
|
||||
test "slice decays to many pointer" {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user