From 06d52f69408299eff611e57b39714b37abbb06a8 Mon Sep 17 00:00:00 2001 From: Michael Forney Date: Thu, 25 Nov 2021 09:42:29 -0800 Subject: Add __builtin_unreachable stub --- cc.h | 1 + expr.c | 4 ++++ qbe.c | 2 ++ scope.c | 1 + 4 files changed, 8 insertions(+) diff --git a/cc.h b/cc.h index 14b71b0..35a8fb8 100644 --- a/cc.h +++ b/cc.h @@ -250,6 +250,7 @@ enum builtinkind { BUILTINNANF, BUILTINOFFSETOF, BUILTINTYPESCOMPATIBLEP, + BUILTINUNREACHABLE, BUILTINVAARG, BUILTINVACOPY, BUILTINVAEND, diff --git a/expr.c b/expr.c index 6ff7dd4..5a8086a 100644 --- a/expr.c +++ b/expr.c @@ -756,6 +756,10 @@ builtinfunc(struct scope *s, enum builtinkind kind) expect(TCOMMA, "after type name"); e = mkconstexpr(&typeint, typecompatible(t, typename(s, NULL))); break; + case BUILTINUNREACHABLE: + e = mkexpr(EXPRBUILTIN, &typevoid, NULL); + e->builtin.kind = BUILTINUNREACHABLE; + break; case BUILTINVAARG: e = mkexpr(EXPRBUILTIN, NULL, assignexpr(s)); e->builtin.kind = BUILTINVAARG; diff --git a/qbe.c b/qbe.c index 264bdac..36fb0e4 100644 --- a/qbe.c +++ b/qbe.c @@ -954,6 +954,8 @@ funcexpr(struct func *f, struct expr *e) case BUILTINALLOCA: l = funcexpr(f, e->base); return funcinst(f, IALLOC16, ptrclass, l, NULL); + case BUILTINUNREACHABLE: + return NULL; default: fatal("internal error: unimplemented builtin"); } diff --git a/scope.c b/scope.c index c116670..299d379 100644 --- a/scope.c +++ b/scope.c @@ -22,6 +22,7 @@ scopeinit(void) {"__builtin_offsetof", {.kind = DECLBUILTIN, .builtin = BUILTINOFFSETOF}}, {"__builtin_types_compatible_p", {.kind = DECLBUILTIN, .builtin = BUILTINTYPESCOMPATIBLEP}}, + {"__builtin_unreachable", {.kind = DECLBUILTIN, .builtin = BUILTINUNREACHABLE}}, {"__builtin_va_arg", {.kind = DECLBUILTIN, .builtin = BUILTINVAARG}}, {"__builtin_va_copy", {.kind = DECLBUILTIN, .builtin = BUILTINVACOPY}}, {"__builtin_va_end", {.kind = DECLBUILTIN, .builtin = BUILTINVAEND}}, -- cgit v1.2.3