inchash::hash hstate;
hstate.add_int (TREE_CODE (type));
- hstate.add_object (TYPE_NAME (type));
+ tree tag = c_type_tag (type);
+ hstate.add_object (tag);
return hstate.end ();
}
previous_tag (tree type)
{
struct c_binding *b = NULL;
- tree name = TYPE_NAME (type);
+ tree name = c_type_tag (type);
if (name)
b = I_TAG_BINDING (name);
}
/* Given a type which could be a typedef name, make sure to return the
- original type. */
+ original type. See set_underlying_type. */
static const_tree
c_type_original (const_tree t)
{
return t;
}
+/* Return the tag for a tagged type. */
+tree
+c_type_tag (const_tree t)
+{
+ gcc_assert (RECORD_OR_UNION_TYPE_P (t) || TREE_CODE (t) == ENUMERAL_TYPE);
+ const_tree orig = c_type_original (t);
+ tree name = TYPE_NAME (orig);
+ if (!name)
+ return NULL_TREE;
+ if (TREE_CODE (name) == TYPE_DECL)
+ {
+ /* A TYPE_DECL added by add_decl_expr. */
+ gcc_checking_assert (!DECL_NAME (name));
+ return NULL_TREE;
+ }
+ gcc_checking_assert (TREE_CODE (name) == IDENTIFIER_NODE);
+ return name;
+}
+
+
\f
/* Return the composite type of two compatible types.
if (flag_isoc23 && !comptypes_same_p (t1, t2))
{
/* Go to the original type to get the right tag. */
- tree tag = TYPE_NAME (c_type_original (const_cast<tree> (t1)));
+ tree tag = c_type_tag (t1);
gcc_checking_assert (COMPLETE_TYPE_P (t1) && COMPLETE_TYPE_P (t2));
gcc_checking_assert (!tag || comptypes (t1, t2));
{
tree s1, s2;
- /* We have to verify that the tags of the types are the same. This
- is harder than it looks because this may be a typedef, so we have
- to go look at the original type. */
- t1 = c_type_original (t1);
- t2 = c_type_original (t2);
- gcc_checking_assert (!TYPE_NAME (t1)
- || TREE_CODE (TYPE_NAME (t1)) == IDENTIFIER_NODE);
- gcc_checking_assert (!TYPE_NAME (t2)
- || TREE_CODE (TYPE_NAME (t2)) == IDENTIFIER_NODE);
-
- if (TYPE_NAME (t1) != TYPE_NAME (t2))
+ if (c_type_tag (t1) != c_type_tag (t2))
return false;
/* When forming equivalence classes for TYPE_CANONICAL in C23, we treat
/* Different types without tag are incompatible except as an anonymous
field or when forming equivalence classes for TYPE_CANONICAL. */
- if (!data->anon_field && !data->equiv && NULL_TREE == TYPE_NAME (t1))
+ if (!data->anon_field && !data->equiv && NULL_TREE == c_type_tag (t1))
return false;
if (!data->anon_field && TYPE_STUB_DECL (t1) != TYPE_STUB_DECL (t2))
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-std=gnu23" } */
+
+int f(int n)
+{
+ struct foo { struct { char (*x)[n]; }; } a;
+ {
+ struct foo { struct { char (*x)[n]; }; } b = a;
+ }
+}
+
+int g(int n)
+{
+ struct foo { struct { char (*x)[n]; }; } a;
+ {
+ struct foo { struct { char (*x)[n]; }; } *b = &a;
+ }
+}
+
+int h(int n)
+{
+ struct foo { struct { struct bar { char (*x)[n]; }* p; }; } a;
+ {
+ struct foo { struct { struct bar { char (*x)[n]; }* p; }; } *b = &a;
+ }
+}
+