~mcf/cproc

07ca02cc2d0a2137433f29186aa838d68ded7e9a — Michael Forney 1 year, 7 months ago b41df7f
Implement __builtin_types_compatible_p

This is used by util-linux.
5 files changed, 14 insertions(+), 0 deletions(-)

M cc.h
M expr.c
M scope.c
A test/builtin-types-compatible-p.c
A test/builtin-types-compatible-p.qbe
M cc.h => cc.h +1 -0
@@ 239,6 239,7 @@ enum builtinkind {
	BUILTININFF,
	BUILTINNANF,
	BUILTINOFFSETOF,
	BUILTINTYPESCOMPATIBLEP,
	BUILTINVAARG,
	BUILTINVACOPY,
	BUILTINVAEND,

M expr.c => expr.c +5 -0
@@ 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;

M scope.c => scope.c +2 -0
@@ 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}},

A test/builtin-types-compatible-p.c => test/builtin-types-compatible-p.c +3 -0
@@ 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 *);

A test/builtin-types-compatible-p.qbe => test/builtin-types-compatible-p.qbe +3 -0
@@ 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, }