aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Forney <mforney@mforney.org>2019-04-16 16:45:14 -0700
committerMichael Forney <mforney@mforney.org>2019-04-16 17:11:41 -0700
commit07ca02cc2d0a2137433f29186aa838d68ded7e9a (patch)
tree90ba44d32a5e9d67eea54b101c9c9d319889867d
parentb41df7f83792799f1a9662b83008ea6f64dc73e1 (diff)
Implement __builtin_types_compatible_p
This is used by util-linux.
-rw-r--r--cc.h1
-rw-r--r--expr.c5
-rw-r--r--scope.c2
-rw-r--r--test/builtin-types-compatible-p.c3
-rw-r--r--test/builtin-types-compatible-p.qbe3
5 files changed, 14 insertions, 0 deletions
diff --git a/cc.h b/cc.h
index 6cf3f94..80cf344 100644
--- a/cc.h
+++ b/cc.h
@@ -239,6 +239,7 @@ enum builtinkind {
BUILTININFF,
BUILTINNANF,
BUILTINOFFSETOF,
+ BUILTINTYPESCOMPATIBLEP,
BUILTINVAARG,
BUILTINVACOPY,
BUILTINVAEND,
diff --git a/expr.c b/expr.c
index 28585c9..5c3e688 100644
--- a/expr.c
+++ b/expr.c
@@ -442,6 +442,11 @@ builtinfunc(struct scope *s, enum builtinkind kind)
e = mkconstexpr(&typeulong, offset);
free(name);
break;
+ case BUILTINTYPESCOMPATIBLEP:
+ t = typename(s, NULL);
+ expect(TCOMMA, "after type name");
+ e = mkconstexpr(&typeint, typecompatible(t, typename(s, NULL)));
+ break;
case BUILTINVAARG:
e = mkexpr(EXPRBUILTIN, NULL);
e->builtin.kind = BUILTINVAARG;
diff --git a/scope.c b/scope.c
index 1dc9f5c..f7207d1 100644
--- a/scope.c
+++ b/scope.c
@@ -20,6 +20,8 @@ scopeinit(void)
{"__builtin_inff", {.kind = DECLBUILTIN, .builtin = BUILTININFF}},
{"__builtin_nanf", {.kind = DECLBUILTIN, .builtin = BUILTINNANF}},
{"__builtin_offsetof", {.kind = DECLBUILTIN, .builtin = BUILTINOFFSETOF}},
+ {"__builtin_types_compatible_p",
+ {.kind = DECLBUILTIN, .builtin = BUILTINTYPESCOMPATIBLEP}},
{"__builtin_va_arg", {.kind = DECLBUILTIN, .builtin = BUILTINVAARG}},
{"__builtin_va_copy", {.kind = DECLBUILTIN, .builtin = BUILTINVACOPY}},
{"__builtin_va_end", {.kind = DECLBUILTIN, .builtin = BUILTINVAEND}},
diff --git a/test/builtin-types-compatible-p.c b/test/builtin-types-compatible-p.c
new file mode 100644
index 0000000..23631ce
--- /dev/null
+++ b/test/builtin-types-compatible-p.c
@@ -0,0 +1,3 @@
+int x = __builtin_types_compatible_p(unsigned, enum {A});
+int y = __builtin_types_compatible_p(const int, int); /* qualifiers are ignored */
+int z = __builtin_types_compatible_p(int *, unsigned *);
diff --git a/test/builtin-types-compatible-p.qbe b/test/builtin-types-compatible-p.qbe
new file mode 100644
index 0000000..cae3e60
--- /dev/null
+++ b/test/builtin-types-compatible-p.qbe
@@ -0,0 +1,3 @@
+export data $x = align 4 { w 1, }
+export data $y = align 4 { w 1, }
+export data $z = align 4 { w 0, }