https://gcc.gnu.org/g:450dc448eabaaf14a3401788028049b27991213c
commit r14-11477-g450dc448eabaaf14a3401788028049b27991213c Author: Martin Uecker <uec...@tugraz.at> Date: Mon Dec 9 12:07:57 2024 +0100 Fix type compatibility for types with flexible array member 1/2 [PR113688,PR114713,PR117724] Allow the TYPE_MODE of a type with an array as last member to differ from another compatible type. gcc/ChangeLog: * tree.cc (gimple_canonical_types_compatible_p): Add exception. (verify_type): Add exception. gcc/lto/ChangeLog: * lto-common.cc (hash_canonical_type): Add exception. (cherry picked from commit 1f48225a0ddfaf74a229105343b22f3086c4b8cb) Diff: --- gcc/lto/lto-common.cc | 3 ++- gcc/tree.cc | 12 +++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/gcc/lto/lto-common.cc b/gcc/lto/lto-common.cc index 2ce94cc32828..f6e08b51dcaf 100644 --- a/gcc/lto/lto-common.cc +++ b/gcc/lto/lto-common.cc @@ -254,7 +254,8 @@ hash_canonical_type (tree type) checked. */ code = tree_code_for_canonical_type_merging (TREE_CODE (type)); hstate.add_int (code); - hstate.add_int (TYPE_MODE (type)); + if (!RECORD_OR_UNION_TYPE_P (type)) + hstate.add_int (TYPE_MODE (type)); /* Incorporate common features of numerical types. */ if (INTEGRAL_TYPE_P (type) diff --git a/gcc/tree.cc b/gcc/tree.cc index d716d7ccfe31..f202187754a6 100644 --- a/gcc/tree.cc +++ b/gcc/tree.cc @@ -13846,8 +13846,11 @@ gimple_canonical_types_compatible_p (const_tree t1, const_tree t2, || TREE_CODE (t1) == NULLPTR_TYPE) return true; - /* Can't be the same type if they have different mode. */ - if (TYPE_MODE (t1) != TYPE_MODE (t2)) + /* Can't be compatible types if they have different mode. Because of + flexible array members, we allow mismatching modes for structures or + unions. */ + if (!RECORD_OR_UNION_TYPE_P (t1) + && TYPE_MODE (t1) != TYPE_MODE (t2)) return false; /* Non-aggregate types can be handled cheaply. */ @@ -14150,8 +14153,11 @@ verify_type (const_tree t) debug_tree (ct); error_found = true; } - if (COMPLETE_TYPE_P (t) && TYPE_CANONICAL (t) + /* We allow a mismatch for structure or union because of + flexible array members. */ + && !RECORD_OR_UNION_TYPE_P (t) + && !RECORD_OR_UNION_TYPE_P (TYPE_CANONICAL (t)) && TYPE_MODE (t) != TYPE_MODE (TYPE_CANONICAL (t))) { error ("%<TYPE_MODE%> of %<TYPE_CANONICAL%> is not compatible");