From eee3756de395ab6220f78b471a7cd877301455a2 Mon Sep 17 00:00:00 2001
From: Jakub Jelinek <jakub@redhat.com>
Date: Fri, 31 Mar 2017 20:40:35 +0200
Subject: [PATCH] re PR bootstrap/79255 (PGO bootstrap fails on x86_64/ppc64le
 building Ada)

	PR debug/79255
	* dwarf2out.c (decls_for_scope): If BLOCK_NONLOCALIZED_VAR is
	a FUNCTION_DECL, pass it as decl instead of origin to
	process_scope_var.

	* gcc.dg/pr79255.c: New test.

From-SVN: r246622
---
 gcc/ChangeLog                  |  7 +++++++
 gcc/dwarf2out.c                |  9 +++++++--
 gcc/testsuite/ChangeLog        |  3 +++
 gcc/testsuite/gcc.dg/pr79255.c | 21 +++++++++++++++++++++
 4 files changed, 38 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/pr79255.c

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 9b257ecb21a9..012d8f825f02 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,10 @@
+2017-03-31  Jakub Jelinek  <jakub@redhat.com>
+
+	PR debug/79255
+	* dwarf2out.c (decls_for_scope): If BLOCK_NONLOCALIZED_VAR is
+	a FUNCTION_DECL, pass it as decl instead of origin to
+	process_scope_var.
+
 2017-03-31  Alexander Monakov  <amonakov@ispras.ru>
 
 	* config/nvptx/nvptx.c (nvptx_output_softstack_switch): Correct format
diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c
index 6ce8fbc95f1d..a00febbc7c8b 100644
--- a/gcc/dwarf2out.c
+++ b/gcc/dwarf2out.c
@@ -24861,8 +24861,13 @@ decls_for_scope (tree stmt, dw_die_ref context_die)
 	 if we've done it once already.  */
       if (! early_dwarf)
 	for (i = 0; i < BLOCK_NUM_NONLOCALIZED_VARS (stmt); i++)
-	  process_scope_var (stmt, NULL, BLOCK_NONLOCALIZED_VAR (stmt, i),
-			     context_die);
+	  {
+	    decl = BLOCK_NONLOCALIZED_VAR (stmt, i);
+	    if (TREE_CODE (decl) == FUNCTION_DECL)
+	      process_scope_var (stmt, decl, NULL_TREE, context_die);
+	    else
+	      process_scope_var (stmt, NULL_TREE, decl, context_die);
+	  }
     }
 
   /* Even if we're at -g1, we need to process the subblocks in order to get
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 134fc2a309c0..d88e067d8405 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,5 +1,8 @@
 2017-03-31  Jakub Jelinek  <jakub@redhat.com>
 
+	PR debug/79255
+	* gcc.dg/pr79255.c: New test.
+
 	PR c++/79572
 	* g++.dg/ubsan/null-8.C: New test.
 
diff --git a/gcc/testsuite/gcc.dg/pr79255.c b/gcc/testsuite/gcc.dg/pr79255.c
new file mode 100644
index 000000000000..bcccec0eec65
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr79255.c
@@ -0,0 +1,21 @@
+/* PR bootstrap/79255 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -g -fno-toplevel-reorder -Wno-attributes" } */
+
+static inline __attribute__((always_inline)) int foo (int x);
+
+int
+baz (void)
+{
+  return foo (3) + foo (6) + foo (9);
+}
+
+static inline __attribute__((always_inline)) int
+foo (int x)
+{
+  auto inline int __attribute__((noinline)) bar (int x)
+  {
+    return x + 3;
+  }
+  return bar (x) + bar (x + 2);
+}
-- 
GitLab