commit 78fe86dcd23821b6a40bc5a0067513c452e50265 (tree)
parent d3eec7d46b1dea6c99dd4beea370a3629843c111
Author: Noam Preil <noam@pixelhero.dev>
Date: Sun, 9 Aug 2020 18:52:32 -0400
CBE: support unreachable on GCC
Diffstat:
3 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/src-self-hosted/cbe.h b/src-self-hosted/cbe.h
@@ -8,3 +8,8 @@
#define zig_noreturn
#endif
+#if __GNUC__
+#define zig_unreachable() __builtin_unreachable()
+#else
+#define zig_unreachable()
+#endif
diff --git a/src-self-hosted/codegen/c.zig b/src-self-hosted/codegen/c.zig
@@ -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 {
diff --git a/test/stage2/cbe.zig b/test/stage2/cbe.zig
@@ -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();
\\}
\\
);