diff options
author | Martin Uecker <uecker@tugraz.at> | 2025-03-01 21:32:21 +0100 |
---|---|---|
committer | Martin Uecker <uecker@gcc.gnu.org> | 2025-03-19 08:53:12 +0100 |
commit | 1636e85270d918a84d57bb521c22c42abf42a47c (patch) | |
tree | 300f437b7e14fd0acaee6738f185c5c19f42090b | |
parent | d9e834958e82219f836577da4ef8176aca2c7c9f (diff) | |
download | gcc-1636e85270d918a84d57bb521c22c42abf42a47c.zip gcc-1636e85270d918a84d57bb521c22c42abf42a47c.tar.gz gcc-1636e85270d918a84d57bb521c22c42abf42a47c.tar.bz2 |
c: Fix bug in typedef redefinitions of tagged types [PR118765]
When we redefine a tagged type we incorrectly update TYPE_STUB_DECL
of the previously defined type instead of the new one. Because
TYPE_STUB_DECL is used when determining whether two such types are
the same, this can cause valid typedef redefinitions to be rejected
later. This is only a partial fix for PR118765.
PR c/118765
gcc/c/ChangeLog:
* c-decl.cc (finish_struct,finish_enum): Swap direction when
copying TYPE_STRUB_DECL in redefinitions.
gcc/testsuite/ChangeLog:
* gcc.dg/pr118765.c: New test.
-rw-r--r-- | gcc/c/c-decl.cc | 4 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/pr118765.c | 7 |
2 files changed, 9 insertions, 2 deletions
diff --git a/gcc/c/c-decl.cc b/gcc/c/c-decl.cc index 0dcbae9..1ae5208 100644 --- a/gcc/c/c-decl.cc +++ b/gcc/c/c-decl.cc @@ -9846,7 +9846,7 @@ finish_struct (location_t loc, tree t, tree fieldlist, tree attributes, && TREE_CODE (vistype) == TREE_CODE (t) && !C_TYPE_BEING_DEFINED (vistype)) { - TYPE_STUB_DECL (vistype) = TYPE_STUB_DECL (t); + TYPE_STUB_DECL (t) = TYPE_STUB_DECL (vistype); if (c_type_variably_modified_p (t)) { error ("redefinition of struct or union %qT with variably " @@ -10321,7 +10321,7 @@ finish_enum (tree enumtype, tree values, tree attributes) && TREE_CODE (vistype) == TREE_CODE (enumtype) && !C_TYPE_BEING_DEFINED (vistype)) { - TYPE_STUB_DECL (vistype) = TYPE_STUB_DECL (enumtype); + TYPE_STUB_DECL (enumtype) = TYPE_STUB_DECL (vistype); if (!comptypes_same_p (enumtype, vistype)) error("conflicting redefinition of enum %qT", enumtype); } diff --git a/gcc/testsuite/gcc.dg/pr118765.c b/gcc/testsuite/gcc.dg/pr118765.c new file mode 100644 index 0000000..12d0259 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr118765.c @@ -0,0 +1,7 @@ +/* { dg-do "compile" } */ +/* { dg-options "-std=gnu23" } */ + +typedef struct q { int x; } q_t; +struct q { int x; }; +typedef struct q { int x; } q_t; + |