Commit 4ec299007a
Changed files (2)
src
test
behavior
src/Sema.zig
@@ -4712,6 +4712,11 @@ fn zirValidateDeref(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr
.Slice => return sema.fail(block, src, "index syntax required for slice type '{}'", .{operand_ty.fmt(sema.mod)}),
}
+ if ((try sema.typeHasOnePossibleValue(operand_ty.childType())) != null) {
+ // No need to validate the actual pointer value, we don't need it!
+ return;
+ }
+
const elem_ty = operand_ty.elemType2();
if (try sema.resolveMaybeUndefVal(operand)) |val| {
if (val.isUndef()) {
test/behavior/comptime_memory.zig
@@ -420,3 +420,11 @@ test "mutate entire slice at comptime" {
buf[1..3].* = x;
}
}
+
+test "dereference undefined pointer to zero-bit type" {
+ const p0: *void = undefined;
+ try testing.expectEqual({}, p0.*);
+
+ const p1: *[0]u32 = undefined;
+ try testing.expect(p1.*.len == 0);
+}