cproc

Unnamed repository; edit this file 'description' to name the repository.
git clone git://git.nihaljere.xyz/cproc
Log | Files | Refs | Submodules | README | LICENSE

commit 3733978d9c7768baaeb6199c05bc98939c15c8cd
parent a056c878d1df67ff12e506d48653c48e9a1b001d
Author: Michael Forney <mforney@mforney.org>
Date:   Fri, 22 Feb 2019 13:48:09 -0800

Implement __builtin_nanf for empty string literals

Diffstat:
Mdecl.h | 1+
Mexpr.c | 8++++++++
Mscope.c | 1+
Atests/builtin-nanf.c | 1+
Atests/builtin-nanf.qbe | 1+
5 files changed, 12 insertions(+), 0 deletions(-)

diff --git a/decl.h b/decl.h @@ -20,6 +20,7 @@ enum builtinkind { BUILTINVAEND, BUILTINOFFSETOF, BUILTINALLOCA, + BUILTINNANF, BUILTININFF, }; diff --git a/expr.c b/expr.c @@ -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 */ diff --git 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_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 @@ -0,0 +1 @@ +float x = __builtin_nanf(""); diff --git a/tests/builtin-nanf.qbe b/tests/builtin-nanf.qbe @@ -0,0 +1 @@ +export data $x = align 4 { s s_nan, }