diff options
author | Michael Forney <mforney@mforney.org> | 2019-02-22 13:48:09 -0800 |
---|---|---|
committer | Michael Forney <mforney@mforney.org> | 2019-02-22 13:50:49 -0800 |
commit | 3733978d9c7768baaeb6199c05bc98939c15c8cd (patch) | |
tree | 3c3de3fc328c69a26a0797896c217204a9f8ff0e | |
parent | a056c878d1df67ff12e506d48653c48e9a1b001d (diff) |
Implement __builtin_nanf for empty string literals
-rw-r--r-- | decl.h | 1 | ||||
-rw-r--r-- | expr.c | 8 | ||||
-rw-r--r-- | scope.c | 1 | ||||
-rw-r--r-- | tests/builtin-nanf.c | 1 | ||||
-rw-r--r-- | tests/builtin-nanf.qbe | 1 |
5 files changed, 12 insertions, 0 deletions
@@ -20,6 +20,7 @@ enum builtinkind { BUILTINVAEND, BUILTINOFFSETOF, BUILTINALLOCA, + BUILTINNANF, BUILTININFF, }; @@ -450,6 +450,14 @@ builtinfunc(struct scope *s, enum builtinkind kind) e->builtin.kind = BUILTINALLOCA; e->builtin.arg = exprconvert(assignexpr(s), &typeulong); break; + case BUILTINNANF: + e = assignexpr(s); + if (!(e->flags & EXPRFLAG_DECAYED) || e->unary.base->kind != EXPRSTRING || e->unary.base->string.size > 0) + error(&tok.loc, "__builtin_nanf currently only supports empty string literals"); + e = mkexpr(EXPRCONST, &typefloat, 0); + /* TODO: use NAN here when we can handle musl's math.h */ + e->constant.f = strtod("nan", NULL); + break; case BUILTININFF: e = mkexpr(EXPRCONST, &typefloat, 0); /* TODO: use INFINITY here when we can handle musl's math.h */ @@ -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_nanf", {.kind = DECLBUILTIN, .builtin = BUILTINNANF}}, {"__builtin_inff", {.kind = DECLBUILTIN, .builtin = BUILTININFF}}, }; struct builtin *b; diff --git a/tests/builtin-nanf.c b/tests/builtin-nanf.c new file mode 100644 index 0000000..d239a46 --- /dev/null +++ b/tests/builtin-nanf.c @@ -0,0 +1 @@ +float x = __builtin_nanf(""); diff --git a/tests/builtin-nanf.qbe b/tests/builtin-nanf.qbe new file mode 100644 index 0000000..5fd7ac2 --- /dev/null +++ b/tests/builtin-nanf.qbe @@ -0,0 +1 @@ +export data $x = align 4 { s s_nan, } |