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