authorgravatar for noam@pixelhero.devNoam Preil <noam@pixelhero.dev> 2020-10-07 02:31:47-04:00
committergravatar for noam@pixelhero.devNoam Preil <noam@pixelhero.dev> 2020-10-07 02:31:47-04:00
logde093879ccc46263c3c6a87173bcf5089d48b4b7
tree441cb297be500d37c6660bb3149e83426f808ffb
parent7b88215a49b2e394508bb8014649747527a4edf6
signaturelock-open Commit is signed but in an unrecognized format.

Fix peer type resolution


2 files changed, 53 insertions(+), 1 deletions(-)

src/Module.zig+5-1
...@@ -2661,11 +2661,15 @@ pub fn resolvePeerTypes(self: *Module, scope: *Scope, instructions: []*Inst) !Ty...@@ -2661,11 +2661,15 @@ pub fn resolvePeerTypes(self: *Module, scope: *Scope, instructions: []*Inst) !Ty
2661 continue;2661 continue;
2662 }2662 }
26632663
2664 if ((prev_inst.ty.zigTypeTag() == .ComptimeInt and next_inst.ty.isInt()) or (next_inst.ty.zigTypeTag() == .ComptimeInt and prev_inst.ty.isInt())) {2664 if (prev_inst.ty.zigTypeTag() == .ComptimeInt and next_inst.ty.isInt()) {
2665 prev_inst = next_inst;2665 prev_inst = next_inst;
2666 continue;2666 continue;
2667 }2667 }
26682668
2669 if (prev_inst.ty.isInt() and next_inst.ty.zigTypeTag() == .ComptimeInt) {
2670 continue;
2671 }
2672
2669 // TODO error notes pointing out each type2673 // TODO error notes pointing out each type
2670 return self.fail(scope, next_inst.src, "incompatible types: '{}' and '{}'", .{ prev_inst.ty, next_inst.ty });2674 return self.fail(scope, next_inst.src, "incompatible types: '{}' and '{}'", .{ prev_inst.ty, next_inst.ty });
2671 }2675 }
test/stage2/cbe.zig+48
...@@ -195,4 +195,52 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -195,4 +195,52 @@ pub fn addCases(ctx: *TestContext) !void {
195 \\}195 \\}
196 \\196 \\
197 );197 );
198 ctx.c("exit with u8 arithmetic inverted", linux_x64,
199 \\export fn _start() noreturn {
200 \\ exitMath(1);
201 \\}
202 \\
203 \\fn exitMath(a: u8) noreturn {
204 \\ exit(a + 0 - a);
205 \\}
206 \\
207 \\fn exit(code: u8) noreturn {
208 \\ asm volatile ("syscall"
209 \\ :
210 \\ : [number] "{rax}" (231),
211 \\ [arg1] "{rdi}" (code)
212 \\ );
213 \\ unreachable;
214 \\}
215 \\
216 ,
217 \\#include <stddef.h>
218 \\#include <stdint.h>
219 \\
220 \\zig_noreturn void exitMath(uint8_t arg0);
221 \\zig_noreturn void exit(uint8_t arg0);
222 \\
223 \\const char *const exit__anon_0 = "{rax}";
224 \\const char *const exit__anon_1 = "{rdi}";
225 \\const char *const exit__anon_2 = "syscall";
226 \\
227 \\zig_noreturn void _start(void) {
228 \\ exitMath(1);
229 \\}
230 \\
231 \\zig_noreturn void exitMath(uint8_t arg0) {
232 \\ const uint8_t __temp_0 = arg0 + 0;
233 \\ const uint8_t __temp_1 = __temp_0 - arg0;
234 \\ exit(__temp_1);
235 \\}
236 \\
237 \\zig_noreturn void exit(uint8_t arg0) {
238 \\ const size_t __temp_0 = (size_t)arg0;
239 \\ register size_t rax_constant __asm__("rax") = 231;
240 \\ register size_t rdi_constant __asm__("rdi") = __temp_0;
241 \\ __asm volatile ("syscall" :: ""(rax_constant), ""(rdi_constant));
242 \\ zig_unreachable();
243 \\}
244 \\
245 );
198}246}