CBE: support unreachable on GCC

This commit is contained in:
Noam Preil 2020-08-09 18:52:32 -04:00 committed by Andrew Kelley
parent d3eec7d46b
commit 78fe86dcd2
3 changed files with 8 additions and 2 deletions

View File

@ -8,3 +8,8 @@
#define zig_noreturn
#endif
#if __GNUC__
#define zig_unreachable() __builtin_unreachable()
#else
#define zig_unreachable()
#endif

View File

@ -178,7 +178,7 @@ fn genBreak(file: *C, inst: *Inst.NoOp, decl: *Decl) !void {
}
fn genUnreach(file: *C, inst: *Inst.NoOp, decl: *Decl) !void {
// TODO ??
try file.main.writer().writeAll(" zig_unreachable();\n");
}
fn genAsm(file: *C, as: *Inst.Assembly, decl: *Decl, argdex: *usize) !void {

View File

@ -65,7 +65,7 @@ pub fn addCases(ctx: *TestContext) !void {
\\}
\\
);
ctx.c("exit", linux_x64,
ctx.c("exit with parameter", linux_x64,
\\export fn _start() noreturn {
\\ exit(0);
\\}
@ -96,6 +96,7 @@ pub fn addCases(ctx: *TestContext) !void {
\\ register size_t rax_constant __asm__("rax") = 231;
\\ register size_t rdi_constant __asm__("rdi") = arg0;
\\ __asm volatile ("syscall" :: ""(rax_constant), ""(rdi_constant));
\\ zig_unreachable();
\\}
\\
);