From fedc9ebd26175bf8309d665f3e1ee6769e8af86d Mon Sep 17 00:00:00 2001 From: jacob gw Date: Wed, 31 Mar 2021 20:16:32 -0400 Subject: [PATCH] stage2: cbe: restore all previously passing tests! --- src/Sema.zig | 8 +- test/stage2/cbe.zig | 180 ++++++++++++++++++++++---------------------- 2 files changed, 96 insertions(+), 92 deletions(-) diff --git a/src/Sema.zig b/src/Sema.zig index 504edfe97b..212db3a0e4 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -3737,8 +3737,12 @@ fn analyzeRet( if (need_coercion) { if (sema.func) |func| { const fn_ty = func.owner_decl.typed_value.most_recent.typed_value.ty; - const casted_operand = try sema.coerce(block, fn_ty.fnReturnType(), operand, src); - _ = try block.addUnOp(src, Type.initTag(.noreturn), .ret, casted_operand); + const fn_ret_ty = fn_ty.fnReturnType(); + const casted_operand = try sema.coerce(block, fn_ret_ty, operand, src); + if (fn_ret_ty.zigTypeTag() == .Void) + _ = try block.addNoOp(src, Type.initTag(.noreturn), .retvoid) + else + _ = try block.addUnOp(src, Type.initTag(.noreturn), .ret, casted_operand); return always_noreturn; } } diff --git a/test/stage2/cbe.zig b/test/stage2/cbe.zig index b79f448e57..2f47b8ebe8 100644 --- a/test/stage2/cbe.zig +++ b/test/stage2/cbe.zig @@ -374,36 +374,36 @@ pub fn addCases(ctx: *TestContext) !void { // , ""); //} - //{ - // var case = ctx.exeFromCompiledC("errors", .{}); - // case.addCompareOutput( - // \\export fn main() c_int { - // \\ var e1 = error.Foo; - // \\ var e2 = error.Bar; - // \\ assert(e1 != e2); - // \\ assert(e1 == error.Foo); - // \\ assert(e2 == error.Bar); - // \\ return 0; - // \\} - // \\fn assert(b: bool) void { - // \\ if (!b) unreachable; - // \\} - // , ""); - // case.addCompareOutput( - // \\export fn main() c_int { - // \\ var e: anyerror!c_int = 0; - // \\ const i = e catch 69; - // \\ return i; - // \\} - // , ""); - // case.addCompareOutput( - // \\export fn main() c_int { - // \\ var e: anyerror!c_int = error.Foo; - // \\ const i = e catch 69; - // \\ return 69 - i; - // \\} - // , ""); - //} + { + var case = ctx.exeFromCompiledC("errors", .{}); + case.addCompareOutput( + \\export fn main() c_int { + \\ var e1 = error.Foo; + \\ var e2 = error.Bar; + \\ assert(e1 != e2); + \\ assert(e1 == error.Foo); + \\ assert(e2 == error.Bar); + \\ return 0; + \\} + \\fn assert(b: bool) void { + \\ if (!b) unreachable; + \\} + , ""); + case.addCompareOutput( + \\export fn main() c_int { + \\ var e: anyerror!c_int = 0; + \\ const i = e catch 69; + \\ return i; + \\} + , ""); + case.addCompareOutput( + \\export fn main() c_int { + \\ var e: anyerror!c_int = error.Foo; + \\ const i = e catch 69; + \\ return 69 - i; + \\} + , ""); + } ctx.c("empty start function", linux_x64, \\export fn _start() noreturn { \\ unreachable; @@ -417,64 +417,64 @@ pub fn addCases(ctx: *TestContext) !void { \\} \\ ); - //ctx.h("simple header", linux_x64, - // \\export fn start() void{} - //, - // \\ZIG_EXTERN_C void start(void); - // \\ - //); - //ctx.h("header with single param function", linux_x64, - // \\export fn start(a: u8) void{} - //, - // \\ZIG_EXTERN_C void start(uint8_t a0); - // \\ - //); - //ctx.h("header with multiple param function", linux_x64, - // \\export fn start(a: u8, b: u8, c: u8) void{} - //, - // \\ZIG_EXTERN_C void start(uint8_t a0, uint8_t a1, uint8_t a2); - // \\ - //); - //ctx.h("header with u32 param function", linux_x64, - // \\export fn start(a: u32) void{} - //, - // \\ZIG_EXTERN_C void start(uint32_t a0); - // \\ - //); - //ctx.h("header with usize param function", linux_x64, - // \\export fn start(a: usize) void{} - //, - // \\ZIG_EXTERN_C void start(uintptr_t a0); - // \\ - //); - //ctx.h("header with bool param function", linux_x64, - // \\export fn start(a: bool) void{} - //, - // \\ZIG_EXTERN_C void start(bool a0); - // \\ - //); - //ctx.h("header with noreturn function", linux_x64, - // \\export fn start() noreturn { - // \\ unreachable; - // \\} - //, - // \\ZIG_EXTERN_C zig_noreturn void start(void); - // \\ - //); - //ctx.h("header with multiple functions", linux_x64, - // \\export fn a() void{} - // \\export fn b() void{} - // \\export fn c() void{} - //, - // \\ZIG_EXTERN_C void a(void); - // \\ZIG_EXTERN_C void b(void); - // \\ZIG_EXTERN_C void c(void); - // \\ - //); - //ctx.h("header with multiple includes", linux_x64, - // \\export fn start(a: u32, b: usize) void{} - //, - // \\ZIG_EXTERN_C void start(uint32_t a0, uintptr_t a1); - // \\ - //); + ctx.h("simple header", linux_x64, + \\export fn start() void{} + , + \\ZIG_EXTERN_C void start(void); + \\ + ); + ctx.h("header with single param function", linux_x64, + \\export fn start(a: u8) void{} + , + \\ZIG_EXTERN_C void start(uint8_t a0); + \\ + ); + ctx.h("header with multiple param function", linux_x64, + \\export fn start(a: u8, b: u8, c: u8) void{} + , + \\ZIG_EXTERN_C void start(uint8_t a0, uint8_t a1, uint8_t a2); + \\ + ); + ctx.h("header with u32 param function", linux_x64, + \\export fn start(a: u32) void{} + , + \\ZIG_EXTERN_C void start(uint32_t a0); + \\ + ); + ctx.h("header with usize param function", linux_x64, + \\export fn start(a: usize) void{} + , + \\ZIG_EXTERN_C void start(uintptr_t a0); + \\ + ); + ctx.h("header with bool param function", linux_x64, + \\export fn start(a: bool) void{} + , + \\ZIG_EXTERN_C void start(bool a0); + \\ + ); + ctx.h("header with noreturn function", linux_x64, + \\export fn start() noreturn { + \\ unreachable; + \\} + , + \\ZIG_EXTERN_C zig_noreturn void start(void); + \\ + ); + ctx.h("header with multiple functions", linux_x64, + \\export fn a() void{} + \\export fn b() void{} + \\export fn c() void{} + , + \\ZIG_EXTERN_C void a(void); + \\ZIG_EXTERN_C void b(void); + \\ZIG_EXTERN_C void c(void); + \\ + ); + ctx.h("header with multiple includes", linux_x64, + \\export fn start(a: u32, b: usize) void{} + , + \\ZIG_EXTERN_C void start(uint32_t a0, uintptr_t a1); + \\ + ); }