]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fix type compatibility for types with flexible array member 1/2 [PR113688,PR114713...
authorMartin Uecker <uecker@tugraz.at>
Mon, 9 Dec 2024 11:07:57 +0000 (12:07 +0100)
committerMartin Uecker <uecker@gcc.gnu.org>
Thu, 12 Dec 2024 12:26:09 +0000 (13:26 +0100)
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.

gcc/lto/lto-common.cc
gcc/tree.cc

index 86a309f92b40a772abee997f1ee511d72a2e8e0e..940502099128fb1652f397fb876f270411adac37 100644 (file)
@@ -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)
index 83a03374a3255d8b8e46bfe9da8759fa2964fbf0..1391af6bd4c3c825883ef9589b2bd86d7f44af0d 100644 (file)
@@ -13914,8 +13914,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.  */
@@ -14218,8 +14221,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");