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

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |accepts-invalid

--- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> ---
The following (otherwise untested) patch detects the problem in the test case.

diff --git a/gcc/cgraphunit.c b/gcc/cgraphunit.c
index 6072c56..635170a 100644
--- a/gcc/cgraphunit.c
+++ b/gcc/cgraphunit.c
@@ -1350,11 +1350,24 @@ handle_alias_pairs (void)
       if (TREE_CODE (p->decl) == FUNCTION_DECL
           && target_node && is_a <cgraph_node *> (target_node))
        {
-         cgraph_node *src_node = cgraph_node::get (p->decl);
-         if (src_node && src_node->definition)
-           src_node->reset ();
-         cgraph_node::create_alias (p->decl, target_node->decl);
-         alias_pairs->unordered_remove (i);
+         tree t1 = TREE_TYPE (p->decl);
+         tree t2 = TREE_TYPE (target_node->decl);
+         if (!gimple_canonical_types_compatible_p (t1, t2, false))
+           {
+             error ("%q+D alias between functions of incompatible types",
+                    p->decl);
+             warning (0, "%q+D aliased declaration",
+                      target_node->decl);
+             alias_pairs->unordered_remove (i);
+           }
+         else
+           {
+             cgraph_node *src_node = cgraph_node::get (p->decl);
+             if (src_node && src_node->definition)
+               src_node->reset ();
+             cgraph_node::create_alias (p->decl, target_node->decl);
+             alias_pairs->unordered_remove (i);
+           }
        }
       else if (VAR_P (p->decl)
               && target_node && is_a <varpool_node *> (target_node))

Reply via email to