Sema: additional check for one-possible-value types in analyzeLoad

This is needed because pointers to zero-bit types are not necessarily
comptime known, but when doing a load, only the element type having one
possible value is relevant.
This commit is contained in:
Andrew Kelley
2022-05-24 18:20:03 -07:00
parent 1f16b07d6f
commit a4ff94804c

View File

@@ -20950,6 +20950,11 @@ fn analyzeLoad(
.Pointer => ptr_ty.childType(),
else => return sema.fail(block, ptr_src, "expected pointer, found '{}'", .{ptr_ty.fmt(sema.mod)}),
};
if (try sema.typeHasOnePossibleValue(block, src, elem_ty)) |opv| {
return sema.addConstant(elem_ty, opv);
}
if (try sema.resolveDefinedValue(block, ptr_src, ptr)) |ptr_val| {
if (try sema.pointerDeref(block, ptr_src, ptr_val, ptr_ty)) |elem_val| {
return sema.addConstant(elem_ty, elem_val);