commit f02b8a9cca4bf991146dab44ef8707b987ce7a1d (tree)
parent 085f6fd8f729423158b6f7a5f8e6f50f78fef18f
Author: Jacob Young <jacobly0@users.noreply.github.com>
Date: Wed, 2 Nov 2022 22:58:55 -0400
cbe: fix padding bits after a bitcast
Diffstat:
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/src/codegen/c.zig b/src/codegen/c.zig
@@ -3703,7 +3703,6 @@ fn airBitcast(f: *Function, inst: Air.Inst.Index) !CValue {
const local = try f.allocLocal(inst_ty, .Const);
try writer.writeAll(" = (");
try f.renderTypecast(writer, inst_ty);
-
try writer.writeByte(')');
try f.writeCValue(writer, operand, .Other);
try writer.writeAll(";\n");
@@ -3721,6 +3720,17 @@ fn airBitcast(f: *Function, inst: Air.Inst.Index) !CValue {
try f.renderTypecast(writer, inst_ty);
try writer.writeAll("));\n");
+ // Ensure padding bits have the expected value.
+ if (inst_ty.isAbiInt()) {
+ try f.writeCValue(writer, local, .Other);
+ try writer.writeAll(" = zig_wrap_");
+ try f.object.dg.renderTypeForBuiltinFnName(writer, inst_ty);
+ try writer.writeByte('(');
+ try f.writeCValue(writer, local, .Other);
+ try f.object.dg.renderBuiltinInfo(writer, inst_ty, .Bits);
+ try writer.writeAll(");\n");
+ }
+
return local;
}