]> git.ipfire.org Git - thirdparty/gcc.git/commit
c: Fix up pointer types to may_alias structures [PR114493]
authorJakub Jelinek <jakub@redhat.com>
Thu, 6 Jun 2024 20:12:11 +0000 (22:12 +0200)
committerJakub Jelinek <jakub@redhat.com>
Tue, 11 Jun 2024 10:35:39 +0000 (12:35 +0200)
commitd4126b329b2ae4f2b60efa1c7ad51b576de168bd
tree5ffe57fb5e11d7b4f251dee57259890f6c6ac9be
parentb065824e30e9168d33b56039e436c4b09078e260
c: Fix up pointer types to may_alias structures [PR114493]

The following testcase ICEs in ipa-free-lang, because the
fld_incomplete_type_of
          gcc_assert (TYPE_CANONICAL (t2) != t2
                      && TYPE_CANONICAL (t2) == TYPE_CANONICAL (TREE_TYPE (t)));
assertion doesn't hold.
This is because t is a struct S * type which was created while struct S
was still incomplete and without the may_alias attribute (and TYPE_CANONICAL
of a pointer type is a type created with can_alias_all = false argument),
while later on on the struct definition may_alias attribute was used.
fld_incomplete_type_of then creates an incomplete distinct copy of the
structure (but with the original attributes) but pointers created for it
are because of the "may_alias" attribute TYPE_REF_CAN_ALIAS_ALL, including
their TYPE_CANONICAL, because while that is created with !can_alias_all
argument, we later set it because of the "may_alias" attribute on the
to_type.

This doesn't ICE with C++ since PR70512 fix because the C++ FE sets
TYPE_REF_CAN_ALIAS_ALL on all pointer types to the class type (and its
variants) when the may_alias is added.

The following patch does that in the C FE as well.

2024-06-06  Jakub Jelinek  <jakub@redhat.com>

PR c/114493
* c-decl.cc (c_fixup_may_alias): New function.
(finish_struct): Call it if "may_alias" attribute is
specified.

* gcc.dg/pr114493-1.c: New test.
* gcc.dg/pr114493-2.c: New test.

(cherry picked from commit d5a3c6d43acb8b2211d9fb59d59482d74c010f01)
gcc/c/c-decl.cc
gcc/testsuite/gcc.dg/pr114493-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/pr114493-2.c [new file with mode: 0644]