Commit 78fe86dcd2

Noam Preil <noam@pixelhero.dev>
2020-08-10 00:52:32
CBE: support unreachable on GCC
1 parent d3eec7d
Changed files (3)
src-self-hosted
codegen
test
stage2
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 {
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
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();
         \\}
         \\
     );