From 9979719a9d0902ffde692ef06e7facf4c1921b99 Mon Sep 17 00:00:00 2001 From: Noam Preil Date: Tue, 8 Sep 2020 14:10:17 -0400 Subject: Stage2 peer type resolution: comptime_int + other_int_type --- src/Module.zig | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/Module.zig') diff --git a/src/Module.zig b/src/Module.zig index 75b6afffcd..151f507ef4 100644 --- a/src/Module.zig +++ b/src/Module.zig @@ -2661,6 +2661,11 @@ pub fn resolvePeerTypes(self: *Module, scope: *Scope, instructions: []*Inst) !Ty continue; } + if (prev_inst.ty.zigTypeTag() == .ComptimeInt and next_inst.ty.isInt()) { + prev_inst = next_inst; + continue; + } + // TODO error notes pointing out each type return self.fail(scope, next_inst.src, "incompatible types: '{}' and '{}'", .{ prev_inst.ty, next_inst.ty }); } -- cgit v1.2.3 From a2e1639d6d10143c91b6c25968cc58f865dbe267 Mon Sep 17 00:00:00 2001 From: Noam Preil Date: Mon, 14 Sep 2020 19:44:32 -0400 Subject: Peer type resolution: comptime_int decay to other int --- src/Module.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Module.zig') diff --git a/src/Module.zig b/src/Module.zig index 151f507ef4..ba79407a80 100644 --- a/src/Module.zig +++ b/src/Module.zig @@ -2661,7 +2661,7 @@ pub fn resolvePeerTypes(self: *Module, scope: *Scope, instructions: []*Inst) !Ty continue; } - if (prev_inst.ty.zigTypeTag() == .ComptimeInt and next_inst.ty.isInt()) { + if ((prev_inst.ty.zigTypeTag() == .ComptimeInt and next_inst.ty.isInt()) or (next_inst.ty.zigTypeTag() == .ComptimeInt and prev_inst.ty.isInt())) { prev_inst = next_inst; continue; } -- cgit v1.2.3 From de093879ccc46263c3c6a87173bcf5089d48b4b7 Mon Sep 17 00:00:00 2001 From: Noam Preil Date: Wed, 7 Oct 2020 02:31:47 -0400 Subject: Fix peer type resolution --- src/Module.zig | 6 +++++- test/stage2/cbe.zig | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) (limited to 'src/Module.zig') 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(); + \\} + \\ + ); } -- cgit v1.2.3 From 7d69e1d84e272251e6aead39c551154797c2b1a4 Mon Sep 17 00:00:00 2001 From: Noam Preil Date: Wed, 7 Oct 2020 02:36:04 -0400 Subject: Rename variables in resolvePeerTypes for clarity --- src/Module.zig | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) (limited to 'src/Module.zig') diff --git a/src/Module.zig b/src/Module.zig index b3bdefceec..1abaf2a63a 100644 --- a/src/Module.zig +++ b/src/Module.zig @@ -2629,52 +2629,52 @@ pub fn resolvePeerTypes(self: *Module, scope: *Scope, instructions: []*Inst) !Ty if (instructions.len == 1) return instructions[0].ty; - var prev_inst = instructions[0]; - for (instructions[1..]) |next_inst| { - if (next_inst.ty.eql(prev_inst.ty)) + var chosen = instructions[0]; + for (instructions[1..]) |candidate| { + if (candidate.ty.eql(chosen.ty)) continue; - if (next_inst.ty.zigTypeTag() == .NoReturn) + if (candidate.ty.zigTypeTag() == .NoReturn) continue; - if (prev_inst.ty.zigTypeTag() == .NoReturn) { - prev_inst = next_inst; + if (chosen.ty.zigTypeTag() == .NoReturn) { + chosen = candidate; continue; } - if (next_inst.ty.zigTypeTag() == .Undefined) + if (candidate.ty.zigTypeTag() == .Undefined) continue; - if (prev_inst.ty.zigTypeTag() == .Undefined) { - prev_inst = next_inst; + if (chosen.ty.zigTypeTag() == .Undefined) { + chosen = candidate; continue; } - if (prev_inst.ty.isInt() and - next_inst.ty.isInt() and - prev_inst.ty.isSignedInt() == next_inst.ty.isSignedInt()) + if (chosen.ty.isInt() and + candidate.ty.isInt() and + chosen.ty.isSignedInt() == candidate.ty.isSignedInt()) { - if (prev_inst.ty.intInfo(self.getTarget()).bits < next_inst.ty.intInfo(self.getTarget()).bits) { - prev_inst = next_inst; + if (chosen.ty.intInfo(self.getTarget()).bits < candidate.ty.intInfo(self.getTarget()).bits) { + chosen = candidate; } continue; } - if (prev_inst.ty.isFloat() and next_inst.ty.isFloat()) { - if (prev_inst.ty.floatBits(self.getTarget()) < next_inst.ty.floatBits(self.getTarget())) { - prev_inst = next_inst; + if (chosen.ty.isFloat() and candidate.ty.isFloat()) { + if (chosen.ty.floatBits(self.getTarget()) < candidate.ty.floatBits(self.getTarget())) { + chosen = candidate; } continue; } - if (prev_inst.ty.zigTypeTag() == .ComptimeInt and next_inst.ty.isInt()) { - prev_inst = next_inst; + if (chosen.ty.zigTypeTag() == .ComptimeInt and candidate.ty.isInt()) { + chosen = candidate; continue; } - if (prev_inst.ty.isInt() and next_inst.ty.zigTypeTag() == .ComptimeInt) { + if (chosen.ty.isInt() and candidate.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 }); + return self.fail(scope, candidate.src, "incompatible types: '{}' and '{}'", .{ chosen.ty, candidate.ty }); } - return prev_inst.ty; + return chosen.ty; } pub fn coerce(self: *Module, scope: *Scope, dest_type: Type, inst: *Inst) !*Inst { -- cgit v1.2.3