]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++/modules: Handle conflicting ABI tags [PR118920]
authorNathaniel Shead <nathanieloshead@gmail.com>
Wed, 26 Mar 2025 12:43:36 +0000 (23:43 +1100)
committerNathaniel Shead <nathanieloshead@gmail.com>
Thu, 27 Mar 2025 12:33:16 +0000 (23:33 +1100)
commit8e99bd447c459d8f298a70355a89122683d7b149
treeac82041075e47a8c70206b3697908a9bfe927233
parent3e0768d2ffde3f20c5baa92d33869f0c196245c4
c++/modules: Handle conflicting ABI tags [PR118920]

The ICE in the linked PR is caused because out_ptr_t inherits an ABI tag
in a module that it does not in the importing module.  When we try to
build a qualified 'const out_ptr_t' during stream-in, we find the
existing 'const out_ptr_t' variant type that has been built, but discard
it due to having a mismatching attribute list.  This causes us to build
a new copy of this variant, and ultimately fail a checking assertion due
to this being an identical type with different TYPE_CANONICAL.

This patch adds checking that ABI tags between an imported and existing
declaration match, and errors if they are incompatible.  We make use of
'equal_abi_tags' from mangle.cc to determine if we should error; in the
case in the PR, because the ABI tag was an implicit tag that doesn't
affect name mangling, we don't need to error.  To fix the ICE we ensure
that (regardless of whether we errored or not) later processing
considers the ABI tags as equivalent.

PR c++/118920

gcc/cp/ChangeLog:

* cp-tree.h (equal_abi_tags): Declare.
* mangle.cc (equal_abi_tags): Make external, fix comparison.
(tree_string_cmp): Make internal.
* module.cc (trees_in::check_abi_tags): New function.
(trees_in::decl_value): Use it.
(trees_in::is_matching_decl): Likewise.

gcc/testsuite/ChangeLog:

* g++.dg/modules/attrib-3_a.H: New test.
* g++.dg/modules/attrib-3_b.C: New test.
* g++.dg/modules/pr118920.h: New test.
* g++.dg/modules/pr118920_a.H: New test.
* g++.dg/modules/pr118920_b.H: New test.
* g++.dg/modules/pr118920_c.C: New test.

Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
Reviewed-by: Jason Merrill <jason@redhat.com>
gcc/cp/cp-tree.h
gcc/cp/mangle.cc
gcc/cp/module.cc
gcc/testsuite/g++.dg/modules/attrib-3_a.H [new file with mode: 0644]
gcc/testsuite/g++.dg/modules/attrib-3_b.C [new file with mode: 0644]
gcc/testsuite/g++.dg/modules/pr118920.h [new file with mode: 0644]
gcc/testsuite/g++.dg/modules/pr118920_a.H [new file with mode: 0644]
gcc/testsuite/g++.dg/modules/pr118920_b.H [new file with mode: 0644]
gcc/testsuite/g++.dg/modules/pr118920_c.C [new file with mode: 0644]