https://gcc.gnu.org/bugzilla/show_bug.cgi?id=41227

--- Comment #15 from Richard Biener <rguenth at gcc dot gnu.org> ---
Ok, the warning is implemented with checking gimple type compatibility in
lto/lto-symtab.c:

      if (!types_compatible_p (TREE_TYPE (prevailing->decl),
                               TREE_TYPE (decl)))
        diagnosed_p |= warning_at (DECL_SOURCE_LOCATION (decl), 0,
                                   "type of %qD does not match original "
                                   "declaration", decl);

I'm not sure it is wise to drop the outermost single-element struct type
from all types during compute of canonical types.

We can adjust gimple_get_alias_set to at least assign the same alias
sets to such struct and its element, but that doesn't cure the warning
(obviously).  At least that avoids generating wrong code... like with

@@ -2307,6 +2308,27 @@ gimple_get_alias_set (tree t)
       || t == unsigned_char_type_node)
     return 0;

+  /* For C, Fortran interoperability assign the same alias-set to
+     a record with a single element as that element.  */
+  if (TREE_CODE (t) == RECORD_TYPE)
+    {
+      tree f = NULL_TREE;
+      for (tree fld = TYPE_FIELDS (t); fld != NULL_TREE; fld = TREE_CHAIN
(fld))
+       {
+         if (TREE_CODE (fld) != FIELD_DECL)
+           continue;
+         if (f == NULL_TREE)
+           f = fld;
+         else
+           {
+             f = NULL_TREE;
+             break;
+           }
+       }
+      if (f)
+       return get_alias_set (TREE_TYPE (f));
+    }
+
   /* Allow aliasing between signed and unsigned variants of the same

but I'm sure we don't want to call get_alias_set on all globals during
WPA phase (Where the warning is emitted).

Humm.  We can special-case that case in lto-symtab.c of course.

Btw, what kind of single-elements can I expect?  I suppose they can
be arbitrary (so aggregate as well)?

Reply via email to