Commit f02b8a9cca

Jacob Young <jacobly0@users.noreply.github.com>
2022-11-03 03:58:55
cbe: fix padding bits after a bitcast
1 parent 085f6fd
Changed files (1)
src
codegen
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;
 }