When checking for compatibility of structure or union types in
tagged_types_tu_compatible_p, restore the old value of the pointer to
the top of the temporary cache after recursively calling comptypes_internal
when looping over the members of a structure of union. While the next
iteration of the loop overwrites the pointer, I missed the fact that it can
be accessed again when types of function arguments are compared as part
of recursive type checking and the function is entered again.
PR c/116726
gcc/c/ChangeLog:
* c-typeck.cc (tagged_types_tu_compatible_p): Restore value
of the cache after recursing into comptypes_internal.
gcc/testsuite/ChangeLog:
* gcc.dg/pr116726.c: New test.
data->anon_field = !DECL_NAME (s1);
data->pointedto = false;
+ const struct tagged_tu_seen_cache *cache = data->cache;
data->cache = &entry;
- if (!comptypes_internal (TREE_TYPE (s1), TREE_TYPE (s2), data))
+ bool ret = comptypes_internal (TREE_TYPE (s1), TREE_TYPE (s2), data);
+ data->cache = cache;
+ if (!ret)
return false;
tree st1 = TYPE_SIZE (TREE_TYPE (s1));
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-std=c23" } */
+
+struct s1 {
+ int f1;
+};
+struct s2 {
+ int f2;
+};
+struct s1 f(struct s2 *);
+
+struct s1 {
+ int f1;
+};
+struct s2 {
+ int f2;
+};
+struct s1 f(struct s2 *);