Skip to content

x86_64: Bug multiplying @as(u17, @intCast(u8)) * comptime_int #19607

@clickingbuttons

Description

@clickingbuttons

Zig Version

0.12.0-dev.3528+423cb317f

Steps to Reproduce and Observed Behavior

pub fn main() !void {
    const a = std.crypto.random.int(u8);
    const b = @as(u17, a) * 60;

    std.debug.print("{}\n", .{ b });
}

pub const std = @import("std");
./zig/build/stage4/bin/zig build-exe ./test.zig -fno-llvm -fno-lld -target x86_64-linux
thread 2176532 panic: access of union field 'load_frame' while field 'immediate' is active

src/zig/src/arch/x86_64/CodeGen.zig:9216:48: 0x10eede63b in genMulDivBinOp (zig)
                    .base = .{ .frame = rhs_mcv.load_frame.index },
                                               ^
src/zig/src/arch/x86_64/CodeGen.zig:4631:56: 0x10ef07003 in airMulWithOverflow (zig)
            const partial_mcv = try self.genMulDivBinOp(.mul, null, dst_ty, src_ty, lhs, rhs);
                                                       ^
src/zig/src/arch/x86_64/CodeGen.zig:2019:62: 0x10ea34b5b in genBody (zig)
            .mul_with_overflow => try self.airMulWithOverflow(inst),
                                                             ^
src/zig/src/arch/x86_64/CodeGen.zig:1820:25: 0x10e4d77eb in gen (zig)
        try self.genBody(self.air.getMainBody());
                        ^

Expected Behavior

No crash. I spent a while reading the Intel developer's manual but now I understand less.

Edit: Remove unnecessary @intcast

Metadata

Metadata

Assignees

No one assigned

    Labels

    arch-x86_6464-bit x86backend-self-hostedbugObserved behavior contradicts documented or intended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions