Sema: bad union field access safety
This commit is contained in:
@@ -504,7 +504,7 @@ pub const DeclGen = struct {
|
||||
if (field_ty.hasRuntimeBitsIgnoreComptime()) {
|
||||
try writer.writeAll("&(");
|
||||
try dg.renderParentPtr(writer, field_ptr.container_ptr, container_ptr_ty);
|
||||
if (field_ptr.container_ty.tag() == .union_tagged) {
|
||||
if (field_ptr.container_ty.tag() == .union_tagged or field_ptr.container_ty.tag() == .union_safety_tagged) {
|
||||
try writer.print(")->payload.{ }", .{fmtIdent(field_name)});
|
||||
} else {
|
||||
try writer.print(")->{ }", .{fmtIdent(field_name)});
|
||||
@@ -842,7 +842,7 @@ pub const DeclGen = struct {
|
||||
try dg.renderTypecast(writer, ty);
|
||||
try writer.writeAll("){");
|
||||
|
||||
if (ty.unionTagType()) |tag_ty| {
|
||||
if (ty.unionTagTypeSafety()) |tag_ty| {
|
||||
if (layout.tag_size != 0) {
|
||||
try writer.writeAll(".tag = ");
|
||||
try dg.renderValue(writer, tag_ty, union_obj.tag, location);
|
||||
@@ -858,7 +858,7 @@ pub const DeclGen = struct {
|
||||
try writer.print(".{ } = ", .{fmtIdent(field_name)});
|
||||
try dg.renderValue(writer, field_ty, union_obj.val, location);
|
||||
}
|
||||
if (ty.unionTagType()) |_| {
|
||||
if (ty.unionTagTypeSafety()) |_| {
|
||||
try writer.writeAll("}");
|
||||
}
|
||||
try writer.writeAll("}");
|
||||
@@ -1110,7 +1110,7 @@ pub const DeclGen = struct {
|
||||
defer buffer.deinit();
|
||||
|
||||
try buffer.appendSlice("typedef ");
|
||||
if (t.unionTagType()) |tag_ty| {
|
||||
if (t.unionTagTypeSafety()) |tag_ty| {
|
||||
const name: CValue = .{ .bytes = "tag" };
|
||||
try buffer.appendSlice("struct {\n ");
|
||||
if (layout.tag_size != 0) {
|
||||
@@ -1134,7 +1134,7 @@ pub const DeclGen = struct {
|
||||
}
|
||||
try buffer.appendSlice("} ");
|
||||
|
||||
if (t.unionTagType()) |_| {
|
||||
if (t.unionTagTypeSafety()) |_| {
|
||||
try buffer.appendSlice("payload;\n} ");
|
||||
}
|
||||
|
||||
@@ -3368,7 +3368,7 @@ fn structFieldPtr(f: *Function, inst: Air.Inst.Index, struct_ptr_ty: Type, struc
|
||||
field_name = fields.keys()[index];
|
||||
field_val_ty = fields.values()[index].ty;
|
||||
},
|
||||
.@"union", .union_tagged => {
|
||||
.@"union", .union_safety_tagged, .union_tagged => {
|
||||
const fields = struct_ty.unionFields();
|
||||
field_name = fields.keys()[index];
|
||||
field_val_ty = fields.values()[index].ty;
|
||||
@@ -3383,7 +3383,7 @@ fn structFieldPtr(f: *Function, inst: Air.Inst.Index, struct_ptr_ty: Type, struc
|
||||
},
|
||||
else => unreachable,
|
||||
}
|
||||
const payload = if (struct_ty.tag() == .union_tagged) "payload." else "";
|
||||
const payload = if (struct_ty.tag() == .union_tagged or struct_ty.tag() == .union_safety_tagged) "payload." else "";
|
||||
|
||||
const inst_ty = f.air.typeOfIndex(inst);
|
||||
const local = try f.allocLocal(inst_ty, .Const);
|
||||
@@ -3415,7 +3415,7 @@ fn airStructFieldVal(f: *Function, inst: Air.Inst.Index) !CValue {
|
||||
defer buf.deinit();
|
||||
const field_name = switch (struct_ty.tag()) {
|
||||
.@"struct" => struct_ty.structFields().keys()[extra.field_index],
|
||||
.@"union", .union_tagged => struct_ty.unionFields().keys()[extra.field_index],
|
||||
.@"union", .union_safety_tagged, .union_tagged => struct_ty.unionFields().keys()[extra.field_index],
|
||||
.tuple, .anon_struct => blk: {
|
||||
const tuple = struct_ty.tupleFields();
|
||||
if (tuple.values[extra.field_index].tag() != .unreachable_value) return CValue.none;
|
||||
@@ -3425,7 +3425,7 @@ fn airStructFieldVal(f: *Function, inst: Air.Inst.Index) !CValue {
|
||||
},
|
||||
else => unreachable,
|
||||
};
|
||||
const payload = if (struct_ty.tag() == .union_tagged) "payload." else "";
|
||||
const payload = if (struct_ty.tag() == .union_tagged or struct_ty.tag() == .union_safety_tagged) "payload." else "";
|
||||
|
||||
const inst_ty = f.air.typeOfIndex(inst);
|
||||
const local = try f.allocLocal(inst_ty, .Const);
|
||||
|
||||
@@ -3404,7 +3404,7 @@ pub const DeclGen = struct {
|
||||
|
||||
if (layout.payload_size == 0) {
|
||||
return lowerValue(dg, .{
|
||||
.ty = tv.ty.unionTagType().?,
|
||||
.ty = tv.ty.unionTagTypeSafety().?,
|
||||
.val = tag_and_val.tag,
|
||||
});
|
||||
}
|
||||
@@ -3446,7 +3446,7 @@ pub const DeclGen = struct {
|
||||
}
|
||||
}
|
||||
const llvm_tag_value = try lowerValue(dg, .{
|
||||
.ty = tv.ty.unionTagType().?,
|
||||
.ty = tv.ty.unionTagTypeSafety().?,
|
||||
.val = tag_and_val.tag,
|
||||
});
|
||||
var fields: [3]*const llvm.Value = undefined;
|
||||
|
||||
Reference in New Issue
Block a user