Skip to content

@shlExact causes illegal hardware instruction on macOS x86_64 #16466

@judofyr

Description

@judofyr

Zig Version

0.11.0-dev.4059+17255bed4

Steps to Reproduce and Observed Behavior

$ cat zig-crash.zig
pub fn main() void {
    const N = @shlExact(1, @as(usize, 3));
    _ = N;
}
$ zig build-exe zig-crash.zig
zsh: illegal hardware instruction  zig build-exe zig-crash.zig

Running zig under a debugger shows that it crashes here:

Process 6618 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)
    frame #0: 0x00000001001d1f0a zig`type.Type.intInfo + 634
zig`type.Type.intInfo:
->  0x1001d1f0a <+634>: ud2
    0x1001d1f0c <+636>: andl   %edi, %edi
Target 0: (zig) stopped.
(lldb) up
frame #1: 0x00000001005de3f6 zig`value.Value.shlWithOverflowScalar + 54
zig`value.Value.shlWithOverflowScalar:
->  0x1005de3f6 <+54>: movdqu (%rbp), %xmm0
    0x1005de3fb <+59>: movdqa %xmm0, 0x10(%rsp)
    0x1005de401 <+65>: leaq   0x30(%rsp), %rdi
    0x1005de406 <+70>: leaq   0x10(%rsp), %rsi
(lldb) up
frame #2: 0x00000001005de91c zig`value.Value.shlWithOverflow + 268
zig`value.Value.shlWithOverflow:
->  0x1005de91c <+268>: movq   0x158(%rsp), %rax
    0x1005de924 <+276>: movq   %rax, 0x20(%rbp)
    0x1005de928 <+280>: movups 0x138(%rsp), %xmm0
    0x1005de930 <+288>: movups 0x148(%rsp), %xmm1

Expected Behavior

The compiler should not crash. I'm not sure if this should produce a compile error (since the first argument is comptime_int) or compile successfully.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behaviorfrontendTokenization, parsing, AstGen, Sema, and Liveness.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions