diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2023-04-25 11:22:15 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2023-04-25 11:23:41 -0700 |
| commit | badad16f88ac7e1eb84eadf76e13b4dc346d4ced (patch) | |
| tree | 990033e793deb56107339304d52fe8ce8bbdfbb3 /src | |
| parent | 401b7f6f537699771ddbc82d524439c5f3db7ea7 (diff) | |
| download | zig-badad16f88ac7e1eb84eadf76e13b4dc346d4ced.tar.gz zig-badad16f88ac7e1eb84eadf76e13b4dc346d4ced.zip | |
C backend: fix lowering comparison when array ptr meets ptr
Pointer comparisons were triggering `-Wcompare-distinct-pointer-types`
before this fix, which adds `(void*)` casts if the lhs type and rhs type
do not match pointer sizeness.
Diffstat (limited to 'src')
| -rw-r--r-- | src/codegen/c.zig | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/src/codegen/c.zig b/src/codegen/c.zig index b60f3553a2..1227b89208 100644 --- a/src/codegen/c.zig +++ b/src/codegen/c.zig @@ -3825,8 +3825,8 @@ fn airCmpOp( data: anytype, operator: std.math.CompareOperator, ) !CValue { - const operand_ty = f.air.typeOf(data.lhs); - const scalar_ty = operand_ty.scalarType(); + const lhs_ty = f.air.typeOf(data.lhs); + const scalar_ty = lhs_ty.scalarType(); const target = f.object.dg.module.getTarget(); const scalar_bits = scalar_ty.bitSize(target); @@ -3847,17 +3847,21 @@ fn airCmpOp( const rhs = try f.resolveInst(data.rhs); try reap(f, inst, &.{ data.lhs, data.rhs }); + const rhs_ty = f.air.typeOf(data.rhs); + const need_cast = lhs_ty.isSinglePointer() != rhs_ty.isSinglePointer(); const writer = f.object.writer(); const local = try f.allocLocal(inst, inst_ty); - const v = try Vectorize.start(f, inst, writer, operand_ty); + const v = try Vectorize.start(f, inst, writer, lhs_ty); try f.writeCValue(writer, local, .Other); try v.elem(f, writer); try writer.writeAll(" = "); + if (need_cast) try writer.writeAll("(void*)"); try f.writeCValue(writer, lhs, .Other); try v.elem(f, writer); try writer.writeByte(' '); try writer.writeAll(compareOperatorC(operator)); try writer.writeByte(' '); + if (need_cast) try writer.writeAll("(void*)"); try f.writeCValue(writer, rhs, .Other); try v.elem(f, writer); try writer.writeAll(";\n"); |
