aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Forney <mforney@mforney.org>2019-02-22 13:16:22 -0800
committerMichael Forney <mforney@mforney.org>2019-02-22 13:50:49 -0800
commit430c38701375d7c3a8176218a8536fd83b52a446 (patch)
tree3cea83c1f42de26ea62eeac76c87b40b6da88ec6
parent4df0c2114cd0afd7aded5e67bd9e9af35b149fab (diff)
downloadcproc-430c38701375d7c3a8176218a8536fd83b52a446.tar.xz
Implement __builtin_inff
-rw-r--r--decl.h1
-rw-r--r--expr.c5
-rw-r--r--scope.c1
-rw-r--r--tests/builtin-inff.c1
-rw-r--r--tests/builtin-inff.qbe1
5 files changed, 9 insertions, 0 deletions
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, }