mirror of
https://github.com/ziglang/zig.git
synced 2026-01-20 14:25:16 +00:00
Sema: use correct value when @ptrCast operand is comptime known
Closes #13034
This commit is contained in:
parent
40578656e8
commit
ba4aa12098
@ -18352,7 +18352,7 @@ fn zirPtrCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
|
||||
return sema.failWithOwnedErrorMsg(msg);
|
||||
}
|
||||
|
||||
if (try sema.resolveMaybeUndefVal(block, operand_src, operand)) |operand_val| {
|
||||
if (try sema.resolveMaybeUndefVal(block, operand_src, ptr)) |operand_val| {
|
||||
if (!dest_ty.ptrAllowsZero() and operand_val.isUndef()) {
|
||||
return sema.failWithUseOfUndef(block, operand_src);
|
||||
}
|
||||
|
||||
@ -483,3 +483,14 @@ test "pointer to constant decl preserves alignment" {
|
||||
const alignment = @typeInfo(@TypeOf(&S.aligned)).Pointer.alignment;
|
||||
try std.testing.expect(alignment == 8);
|
||||
}
|
||||
|
||||
test "ptrCast comptime known slice to C pointer" {
|
||||
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
|
||||
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
|
||||
if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
|
||||
if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
|
||||
|
||||
const s: [:0]const u8 = "foo";
|
||||
var p = @ptrCast([*c]const u8, s);
|
||||
try std.testing.expectEqualStrings(s, std.mem.sliceTo(p, 0));
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user