mirror of
https://github.com/frida/tinycc
synced 2024-12-24 14:06:48 +03:00
Fix how _Generic treats pointers to arrays.
_Generic should distinguish pointers to differently sized arrays such as `int(*)[2]` and `int(*)[4]`.
This commit is contained in:
parent
73ca09ff32
commit
314843ffc3
5
tccgen.c
5
tccgen.c
@ -2820,11 +2820,14 @@ static int compare_types(CType *type1, CType *type2, int unqualified)
|
||||
if (t1 != t2)
|
||||
return 0;
|
||||
/* test more complicated cases */
|
||||
bt1 = t1 & VT_BTYPE;
|
||||
bt1 = t1 & (VT_BTYPE | (unqualified ? 0 : VT_ARRAY) );
|
||||
if (bt1 == VT_PTR) {
|
||||
type1 = pointed_type(type1);
|
||||
type2 = pointed_type(type2);
|
||||
return is_compatible_types(type1, type2);
|
||||
} else if (bt1 & VT_ARRAY) {
|
||||
return type1->ref->c < 0 || type2->ref->c < 0
|
||||
|| type1->ref->c == type2->ref->c;
|
||||
} else if (bt1 == VT_STRUCT) {
|
||||
return (type1->ref == type2->ref);
|
||||
} else if (bt1 == VT_FUNC) {
|
||||
|
@ -68,5 +68,8 @@ int main()
|
||||
printf("%d\n", i);
|
||||
i = _Generic(foo, fptr: 3, int: 4);
|
||||
printf("%d\n", i);
|
||||
|
||||
(void)_Generic((int(*)[2]){0}, int(*)[2]:0, int(*)[4]:0); //shouldn't match twice
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user