This is a regression present on the mainline for weak external symbols and 
languages with non-call exceptions:

0xb222df crash_signal
        /home/eric/svn/gcc/gcc/toplev.c:337
0x75ed9c symtab_alias_ultimate_target(symtab_node*, availability*)
        /home/eric/svn/gcc/gcc/symtab.c:989
0xb69a59 varpool_variable_node
        /home/eric/svn/gcc/gcc/cgraph.h:1430
0xb69a59 tree_could_trap_p(tree_node*)
        /home/eric/svn/gcc/gcc/tree-eh.c:2691
0xb6a85c stmt_could_throw_1_p
        /home/eric/svn/gcc/gcc/tree-eh.c:2751
0xb6a85c stmt_could_throw_p(gimple_statement_base*)
        /home/eric/svn/gcc/gcc/tree-eh.c:2780
0xb6d46f lower_eh_constructs_2
        /home/eric/svn/gcc/gcc/tree-eh.c:2028
0xb6d46f lower_eh_constructs_1
        /home/eric/svn/gcc/gcc/tree-eh.c:2123
0xb6f871 lower_eh_constructs
        /home/eric/svn/gcc/gcc/tree-eh.c:2141
0xb6f871 execute
        /home/eric/svn/gcc/gcc/tree-eh.c:2193
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <http://gcc.gnu.org/bugs.html> for instructions.

In tree_could_trap_p:

    case VAR_DECL:
      /* Assume that accesses to weak vars may trap, unless we know
         they are certainly defined in current TU or in some other
         LTO partition.  */
      if (DECL_WEAK (expr))
        {
          struct varpool_node *node;
          if (!DECL_EXTERNAL (expr))
            return false;
          node = varpool_variable_node (varpool_get_node (expr), NULL);
          if (node && node->symbol.in_other_partition)
            return false;
          return true;
        }
      return false;

The problem is that varpool_get_node returns NULL and varpool_variable_node
(and its callee symtab_alias_ultimate_target) chokes on the NULL.  This is
a regression from the 4.8.x series, where the same NULL goes through the
function without a hitch.

Tested on x86_64-suse-linux, applied on the mainline as obvious.


2014-01-08  Eric Botcazou  <ebotca...@adacore.com>

        * cgraph.h (varpool_variable_node): Do not choke on null node.


2014-01-08  Eric Botcazou  <ebotca...@adacore.com>

        * gnat.dg/weak2.ad[sb]: New test.


-- 
Eric Botcazou
Index: cgraph.h
===================================================================
--- cgraph.h	(revision 206418)
+++ cgraph.h	(working copy)
@@ -1426,8 +1426,12 @@ varpool_variable_node (varpool_node *nod
 {
   varpool_node *n;
 
-  n = dyn_cast <varpool_node> (symtab_alias_ultimate_target (node,
-							     availability));
+  if (node)
+    n = dyn_cast <varpool_node> (symtab_alias_ultimate_target (node,
+							       availability));
+  else
+    n = NULL;
+
   if (!n && availability)
     *availability = AVAIL_NOT_AVAILABLE;
   return n;
-- { dg-do compile }

package body Weak2 is

   function F return Integer is
   begin
      return Var;
   end;

end Weak2;
package Weak2 is

   Var : Integer;
   pragma Import (Ada, Var, "var_name");
   pragma Weak_External (Var);

   function F return Integer;

end Weak2;

Reply via email to