Commit 6553359f39

Jacob Young <jacobly0@users.noreply.github.com>
2023-11-04 09:58:42
x86_64: fix ub that the llvm backend was hiding
1 parent 7b1a644
Changed files (1)
src
arch
src/arch/x86_64/Encoding.zig
@@ -62,8 +62,7 @@ pub fn findByMnemonic(
             .rex, .rex_short => if (!rex_required) continue,
             else => {},
         }
-        for (input_ops, data.ops) |input_op, data_op|
-            if (!input_op.isSubset(data_op)) continue :next;
+        for (input_ops, data.ops) |input_op, data_op| if (!input_op.isSubset(data_op)) continue :next;
 
         const enc = Encoding{ .mnemonic = mnemonic, .data = data };
         if (shortest_enc) |previous_shortest_enc| {
@@ -828,18 +827,13 @@ const mnemonic_to_encodings_map = init: {
     for (&data_storage, entries, 0..) |*data, entry, data_index| {
         data.* = .{
             .op_en = entry[1],
-            .ops = undefined,
+            .ops = (entry[2] ++ .{.none} ** (data.ops.len - entry[2].len)).*,
             .opc_len = entry[3].len,
-            .opc = undefined,
+            .opc = (entry[3] ++ .{undefined} ** (data.opc.len - entry[3].len)).*,
             .modrm_ext = entry[4],
             .mode = entry[5],
             .feature = entry[6],
         };
-        // TODO: use `@memcpy` for these. When I did that, I got a false positive
-        // compile error for this copy happening at compile time.
-        std.mem.copyForwards(Op, &data.ops, entry[2]);
-        std.mem.copyForwards(u8, &data.opc, entry[3]);
-
         while (mnemonic_int < @intFromEnum(entry[0])) : (mnemonic_int += 1) {
             mnemonic_map[mnemonic_int] = data_storage[mnemonic_start..data_index];
             mnemonic_start = data_index;