From 430c38701375d7c3a8176218a8536fd83b52a446 Mon Sep 17 00:00:00 2001 From: Michael Forney Date: Fri, 22 Feb 2019 13:16:22 -0800 Subject: Implement __builtin_inff --- decl.h | 1 + expr.c | 5 +++++ scope.c | 1 + tests/builtin-inff.c | 1 + tests/builtin-inff.qbe | 1 + 5 files changed, 9 insertions(+) create mode 100644 tests/builtin-inff.c create mode 100644 tests/builtin-inff.qbe diff --git a/decl.h b/decl.h index 5b8b83d..db6a28c 100644 --- a/decl.h +++ b/decl.h @@ -20,6 +20,7 @@ enum builtinkind { BUILTINVAEND, BUILTINOFFSETOF, BUILTINALLOCA, + BUILTININFF, }; struct declaration { diff --git a/expr.c b/expr.c index 30399e5..8e8a7ca 100644 --- a/expr.c +++ b/expr.c @@ -481,6 +481,11 @@ postfixexpr(struct scope *s, struct expression *r) e->builtin.kind = BUILTINALLOCA; e->builtin.arg = exprconvert(assignexpr(s), &typeulong); break; + case BUILTININFF: + e = mkexpr(EXPRCONST, &typefloat, 0); + /* TODO: use INFINITY here when we can handle musl's math.h */ + e->constant.f = strtod("inf", NULL); + break; default: fatal("internal error; unknown builtin"); } diff --git a/scope.c b/scope.c index bd550e8..00569b9 100644 --- a/scope.c +++ b/scope.c @@ -24,6 +24,7 @@ scopeinit(void) {"__builtin_va_end", {.kind = DECLBUILTIN, .builtin = BUILTINVAEND}}, {"__builtin_offsetof", {.kind = DECLBUILTIN, .builtin = BUILTINOFFSETOF}}, {"__builtin_alloca", {.kind = DECLBUILTIN, .builtin = BUILTINALLOCA}}, + {"__builtin_inff", {.kind = DECLBUILTIN, .builtin = BUILTININFF}}, }; struct builtin *b; diff --git a/tests/builtin-inff.c b/tests/builtin-inff.c new file mode 100644 index 0000000..2dcd040 --- /dev/null +++ b/tests/builtin-inff.c @@ -0,0 +1 @@ +float x = __builtin_inff(); diff --git a/tests/builtin-inff.qbe b/tests/builtin-inff.qbe new file mode 100644 index 0000000..5eb8060 --- /dev/null +++ b/tests/builtin-inff.qbe @@ -0,0 +1 @@ +export data $x = align 4 { s s_inf, } -- cgit v1.2.3