cbe: fix indexing with a zero-bit element type
Fixes void dereference warnings on gcc 11.3.0.
This commit is contained in:
@@ -2658,12 +2658,14 @@ fn airPtrElemPtr(f: *Function, inst: Air.Inst.Index) !CValue {
|
||||
const ty_pl = f.air.instructions.items(.data)[inst].ty_pl;
|
||||
const bin_op = f.air.extraData(Air.Bin, ty_pl.payload).data;
|
||||
const ptr_ty = f.air.typeOf(bin_op.lhs);
|
||||
const child_ty = ptr_ty.childType();
|
||||
|
||||
const ptr = try f.resolveInst(bin_op.lhs);
|
||||
if (!child_ty.hasRuntimeBitsIgnoreComptime()) return ptr;
|
||||
const index = try f.resolveInst(bin_op.rhs);
|
||||
|
||||
const writer = f.object.writer();
|
||||
const local = try f.allocLocal(f.air.typeOfIndex(inst), .Const);
|
||||
|
||||
try writer.writeAll(" = &(");
|
||||
if (ptr_ty.ptrSize() == .One) {
|
||||
// It's a pointer to an array, so we need to de-reference.
|
||||
@@ -2717,15 +2719,23 @@ fn airSliceElemPtr(f: *Function, inst: Air.Inst.Index) !CValue {
|
||||
const ty_pl = f.air.instructions.items(.data)[inst].ty_pl;
|
||||
const bin_op = f.air.extraData(Air.Bin, ty_pl.payload).data;
|
||||
|
||||
const slice_ty = f.air.typeOf(bin_op.lhs);
|
||||
const child_ty = slice_ty.elemType2();
|
||||
const slice = try f.resolveInst(bin_op.lhs);
|
||||
const index = try f.resolveInst(bin_op.rhs);
|
||||
|
||||
const writer = f.object.writer();
|
||||
const local = try f.allocLocal(f.air.typeOfIndex(inst), .Const);
|
||||
try writer.writeAll(" = &");
|
||||
try writer.writeAll(" = ");
|
||||
if (child_ty.hasRuntimeBitsIgnoreComptime()) try writer.writeByte('&');
|
||||
try f.writeCValue(writer, slice, .Other);
|
||||
try writer.writeAll(".ptr[");
|
||||
try f.writeCValue(writer, index, .Other);
|
||||
try writer.writeAll("];\n");
|
||||
try writer.writeAll(".ptr");
|
||||
if (child_ty.hasRuntimeBitsIgnoreComptime()) {
|
||||
const index = try f.resolveInst(bin_op.rhs);
|
||||
try writer.writeByte('[');
|
||||
try f.writeCValue(writer, index, .Other);
|
||||
try writer.writeByte(']');
|
||||
}
|
||||
try writer.writeAll(";\n");
|
||||
return local;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user