aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cc.h1
-rw-r--r--expr.c7
-rw-r--r--scope.c1
-rw-r--r--test/builtin-expect.c4
-rw-r--r--test/builtin-expect.qbe8
5 files changed, 21 insertions, 0 deletions
diff --git a/cc.h b/cc.h
index 0c0d08b..9b0989e 100644
--- a/cc.h
+++ b/cc.h
@@ -236,6 +236,7 @@ enum linkage {
enum builtinkind {
BUILTINALLOCA,
BUILTINCONSTANTP,
+ BUILTINEXPECT,
BUILTININFF,
BUILTINNANF,
BUILTINOFFSETOF,
diff --git a/expr.c b/expr.c
index 591d80a..171c239 100644
--- a/expr.c
+++ b/expr.c
@@ -565,6 +565,13 @@ builtinfunc(struct scope *s, enum builtinkind kind)
case BUILTINCONSTANTP:
e = mkconstexpr(&typeint, eval(condexpr(s), EVALARITH)->kind == EXPRCONST);
break;
+ case BUILTINEXPECT:
+ /* just a no-op for now */
+ /* TODO: check that the expression and the expected value have type 'long' */
+ e = assignexpr(s);
+ expect(TCOMMA, "after expression");
+ delexpr(assignexpr(s));
+ break;
case BUILTININFF:
e = mkexpr(EXPRCONST, &typefloat);
/* TODO: use INFINITY here when we can handle musl's math.h */
diff --git a/scope.c b/scope.c
index 615d1fe..72025f5 100644
--- a/scope.c
+++ b/scope.c
@@ -16,6 +16,7 @@ scopeinit(void)
} builtins[] = {
{"__builtin_alloca", {.kind = DECLBUILTIN, .builtin = BUILTINALLOCA}},
{"__builtin_constant_p", {.kind = DECLBUILTIN, .builtin = BUILTINCONSTANTP}},
+ {"__builtin_expect", {.kind = DECLBUILTIN, .builtin = BUILTINEXPECT}},
{"__builtin_inff", {.kind = DECLBUILTIN, .builtin = BUILTININFF}},
{"__builtin_nanf", {.kind = DECLBUILTIN, .builtin = BUILTINNANF}},
{"__builtin_offsetof", {.kind = DECLBUILTIN, .builtin = BUILTINOFFSETOF}},
diff --git a/test/builtin-expect.c b/test/builtin-expect.c
new file mode 100644
index 0000000..aac5ede
--- /dev/null
+++ b/test/builtin-expect.c
@@ -0,0 +1,4 @@
+int x;
+int main(void) {
+ return __builtin_expect(x, 0);
+}
diff --git a/test/builtin-expect.qbe b/test/builtin-expect.qbe
new file mode 100644
index 0000000..73e3b42
--- /dev/null
+++ b/test/builtin-expect.qbe
@@ -0,0 +1,8 @@
+export
+function w $main() {
+@start.1
+@body.2
+ %.1 =w loadsw $x
+ ret %.1
+}
+export data $x = align 4 { z 4 }