diff --git a/src/Module.zig b/src/Module.zig index ba79407a80..b3bdefceec 100644 --- a/src/Module.zig +++ b/src/Module.zig @@ -2661,11 +2661,15 @@ pub fn resolvePeerTypes(self: *Module, scope: *Scope, instructions: []*Inst) !Ty continue; } - if ((prev_inst.ty.zigTypeTag() == .ComptimeInt and next_inst.ty.isInt()) or (next_inst.ty.zigTypeTag() == .ComptimeInt and prev_inst.ty.isInt())) { + if (prev_inst.ty.zigTypeTag() == .ComptimeInt and next_inst.ty.isInt()) { prev_inst = next_inst; continue; } + if (prev_inst.ty.isInt() and next_inst.ty.zigTypeTag() == .ComptimeInt) { + continue; + } + // TODO error notes pointing out each type return self.fail(scope, next_inst.src, "incompatible types: '{}' and '{}'", .{ prev_inst.ty, next_inst.ty }); } diff --git a/test/stage2/cbe.zig b/test/stage2/cbe.zig index 0be5bd8704..fbf0f9e708 100644 --- a/test/stage2/cbe.zig +++ b/test/stage2/cbe.zig @@ -195,4 +195,52 @@ pub fn addCases(ctx: *TestContext) !void { \\} \\ ); + ctx.c("exit with u8 arithmetic inverted", linux_x64, + \\export fn _start() noreturn { + \\ exitMath(1); + \\} + \\ + \\fn exitMath(a: u8) noreturn { + \\ exit(a + 0 - a); + \\} + \\ + \\fn exit(code: u8) noreturn { + \\ asm volatile ("syscall" + \\ : + \\ : [number] "{rax}" (231), + \\ [arg1] "{rdi}" (code) + \\ ); + \\ unreachable; + \\} + \\ + , + \\#include + \\#include + \\ + \\zig_noreturn void exitMath(uint8_t arg0); + \\zig_noreturn void exit(uint8_t arg0); + \\ + \\const char *const exit__anon_0 = "{rax}"; + \\const char *const exit__anon_1 = "{rdi}"; + \\const char *const exit__anon_2 = "syscall"; + \\ + \\zig_noreturn void _start(void) { + \\ exitMath(1); + \\} + \\ + \\zig_noreturn void exitMath(uint8_t arg0) { + \\ const uint8_t __temp_0 = arg0 + 0; + \\ const uint8_t __temp_1 = __temp_0 - arg0; + \\ exit(__temp_1); + \\} + \\ + \\zig_noreturn void exit(uint8_t arg0) { + \\ const size_t __temp_0 = (size_t)arg0; + \\ register size_t rax_constant __asm__("rax") = 231; + \\ register size_t rdi_constant __asm__("rdi") = __temp_0; + \\ __asm volatile ("syscall" :: ""(rax_constant), ""(rdi_constant)); + \\ zig_unreachable(); + \\} + \\ + ); }