From 4666db3288a9c19754870530a9a819ebd7e4d682 Mon Sep 17 00:00:00 2001 From: Christopher Bazley Date: Sun, 6 Sep 2026 19:53:57 +0100 Subject: [PATCH] tccgen: match GCC for qualified array types __builtin_types_compatible_p ignores qualifiers exposed through array type derivations in GCC and Clang, whereas it does not in TCC. This fix uses the existing unqualified comparison recursively for array types, while continuing to preserve qualifiers on referenced types. --- tccgen.c | 6 +++--- tests/tcctest.c | 3 +++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/tccgen.c b/tccgen.c index 8f4cd13a..fa190597 100644 --- a/tccgen.c +++ b/tccgen.c @@ -2893,6 +2893,8 @@ static int compare_types(CType *type1, CType *type2, int unqualified) if (bt1 == VT_PTR) { type1 = pointed_type(type1); type2 = pointed_type(type2); + if (unqualified && (t1 & VT_ARRAY)) + return compare_types(type1, type2, 1); return is_compatible_types(type1, type2); } else if (bt1 == VT_STRUCT) { return (type1->ref == type2->ref); @@ -5815,9 +5817,7 @@ ST_FUNC void unary(void) break; case TOK_builtin_types_compatible_p: parse_builtin_params(0, "tt"); - vtop[-1].type.t &= ~(VT_CONSTANT | VT_VOLATILE); - vtop[0].type.t &= ~(VT_CONSTANT | VT_VOLATILE); - n = is_compatible_types(&vtop[-1].type, &vtop[0].type); + n = compare_types(&vtop[-1].type, &vtop[0].type, 1); vtop -= 2; vpushi(n); break; diff --git a/tests/tcctest.c b/tests/tcctest.c index 38d27fcf..e275bf6c 100644 --- a/tests/tcctest.c +++ b/tests/tcctest.c @@ -3953,6 +3953,9 @@ void builtin_test(void) COMPAT_TYPE(int, char); COMPAT_TYPE(int, const int); COMPAT_TYPE(int, volatile int); + COMPAT_TYPE(int[2], const int[2]); + COMPAT_TYPE(int[2][3], volatile int[][3]); + COMPAT_TYPE(int (*)[], const int (*)[]); COMPAT_TYPE(int *, int *); COMPAT_TYPE(int *, void *); COMPAT_TYPE(int *, const int *);