56d343
2015-12-02  Pierre-Marie de Rodat  <derodat@adacore.com>
56d343
56d343
	* dwarf2out.c (dwar2out_var_location): Enhance pattern matching to get
56d343
	the SYMBOL_REF they embed.
56d343
	(gen_subprogram_die): Handle such calls.
56d343
56d343
--- gcc/dwarf2out.c	(revision 231184)
56d343
+++ gcc/dwarf2out.c	(revision 231185)
56d343
@@ -18051,18 +18051,23 @@ gen_subprogram_die (tree decl, dw_die_re
56d343
 		    }
56d343
 		  if (mode == VOIDmode || mode == BLKmode)
56d343
 		    continue;
56d343
-		  if (XEXP (XEXP (arg, 0), 0) == pc_rtx)
56d343
+		  /* Get dynamic information about call target only if we
56d343
+		     have no static information: we cannot generate both
56d343
+		     DW_AT_abstract_origin and DW_AT_GNU_call_site_target
56d343
+		     attributes.  */
56d343
+		  if (ca_loc->symbol_ref == NULL_RTX)
56d343
 		    {
56d343
-		      gcc_assert (ca_loc->symbol_ref == NULL_RTX);
56d343
-		      tloc = XEXP (XEXP (arg, 0), 1);
56d343
-		      continue;
56d343
-		    }
56d343
-		  else if (GET_CODE (XEXP (XEXP (arg, 0), 0)) == CLOBBER
56d343
-			   && XEXP (XEXP (XEXP (arg, 0), 0), 0) == pc_rtx)
56d343
-		    {
56d343
-		      gcc_assert (ca_loc->symbol_ref == NULL_RTX);
56d343
-		      tlocc = XEXP (XEXP (arg, 0), 1);
56d343
-		      continue;
56d343
+		      if (XEXP (XEXP (arg, 0), 0) == pc_rtx)
56d343
+			{
56d343
+			  tloc = XEXP (XEXP (arg, 0), 1);
56d343
+			  continue;
56d343
+			}
56d343
+		      else if (GET_CODE (XEXP (XEXP (arg, 0), 0)) == CLOBBER
56d343
+			       && XEXP (XEXP (XEXP (arg, 0), 0), 0) == pc_rtx)
56d343
+			{
56d343
+			  tlocc = XEXP (XEXP (arg, 0), 1);
56d343
+			  continue;
56d343
+			}
56d343
 		    }
56d343
 		  reg = NULL;
56d343
 		  if (REG_P (XEXP (XEXP (arg, 0), 0)))
56d343
@@ -20842,15 +20847,27 @@ dwarf2out_var_location (rtx loc_note)
56d343
       if (!CALL_P (prev))
56d343
 	prev = XVECEXP (PATTERN (prev), 0, 0);
56d343
       ca_loc->tail_call_p = SIBLING_CALL_P (prev);
56d343
+
56d343
+      /* Look for a SYMBOL_REF in the "prev" instruction.  */
56d343
       x = get_call_rtx_from (PATTERN (prev));
56d343
       if (x)
56d343
 	{
56d343
-	  x = XEXP (XEXP (x, 0), 0);
56d343
-	  if (GET_CODE (x) == SYMBOL_REF
56d343
-	      && SYMBOL_REF_DECL (x)
56d343
-	      && TREE_CODE (SYMBOL_REF_DECL (x)) == FUNCTION_DECL)
56d343
-	    ca_loc->symbol_ref = x;
56d343
+	  /* Try to get the call symbol, if any.  */
56d343
+	  if (MEM_P (XEXP (x, 0)))
56d343
+	    x = XEXP (x, 0);
56d343
+	  /* First, look for a memory access to a symbol_ref.  */
56d343
+	  if (GET_CODE (XEXP (x, 0)) == SYMBOL_REF
56d343
+	      && SYMBOL_REF_DECL (XEXP (x, 0))
56d343
+	      && TREE_CODE (SYMBOL_REF_DECL (XEXP (x, 0))) == FUNCTION_DECL)
56d343
+	    ca_loc->symbol_ref = XEXP (x, 0);
56d343
+	  /* Otherwise, look at a compile-time known user-level function
56d343
+	     declaration.  */
56d343
+	  else if (MEM_P (x)
56d343
+		   && MEM_EXPR (x)
56d343
+		   && TREE_CODE (MEM_EXPR (x)) == FUNCTION_DECL)
56d343
+	    ca_loc->symbol_ref = XEXP (DECL_RTL (MEM_EXPR (x)), 0);
56d343
 	}
56d343
+
56d343
       ca_loc->block = insn_scope (prev);
56d343
       if (call_arg_locations)
56d343
 	call_arg_loc_last->next = ca_loc;