Hello.

There's a series of patches that I installed to GCC6 and majority of there
are also related to GCC 5 branch.

I'm going to install the patches.
Martin

>From 9cbe2ada95218219ca1de6e5d9c839509f8cd6ab Mon Sep 17 00:00:00 2001
From: marxin <marxin@138bc75d-0d04-0410-961f-82ee72b054a4>
Date: Tue, 28 Mar 2017 09:01:57 +0000
Subject: [PATCH 01/12] Backport r246525

gcc/ChangeLog:

2017-03-28  Martin Liska  <mli...@suse.cz>

	PR ipa/80104
	* cgraphunit.c (cgraph_node::expand_thunk): Mark argument of a
	thunk call as DECL_GIMPLE_REG_P when vector or complex type.

gcc/testsuite/ChangeLog:

2017-03-28  Martin Liska  <mli...@suse.cz>

	PR ipa/80104
	* gcc.dg/ipa/pr80104.c: New test.
---
 gcc/cgraphunit.c                   |  4 ++++
 gcc/testsuite/gcc.dg/ipa/pr80104.c | 15 +++++++++++++++
 2 files changed, 19 insertions(+)
 create mode 100644 gcc/testsuite/gcc.dg/ipa/pr80104.c

diff --git a/gcc/cgraphunit.c b/gcc/cgraphunit.c
index d4db126cbd5..5f0b06ebec0 100644
--- a/gcc/cgraphunit.c
+++ b/gcc/cgraphunit.c
@@ -1673,6 +1673,10 @@ cgraph_node::expand_thunk (bool output_asm_thunks, bool force_gimple_thunk)
 	for (; i < nargs; i++, arg = DECL_CHAIN (arg))
 	  {
 	    tree tmp = arg;
+	    if (VECTOR_TYPE_P (TREE_TYPE (arg))
+		|| TREE_CODE (TREE_TYPE (arg)) == COMPLEX_TYPE)
+	      DECL_GIMPLE_REG_P (arg) = 1;
+
 	    if (!is_gimple_val (arg))
 	      {
 		tmp = create_tmp_reg (TYPE_MAIN_VARIANT
diff --git a/gcc/testsuite/gcc.dg/ipa/pr80104.c b/gcc/testsuite/gcc.dg/ipa/pr80104.c
new file mode 100644
index 00000000000..7e75c9907e7
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/ipa/pr80104.c
@@ -0,0 +1,15 @@
+/* PR ipa/80104 */
+/* { dg-do compile } */
+/* { dg-options "-fipa-icf" } */
+
+float
+a (_Complex float b)
+{
+  return *&b;
+}
+
+float
+c (_Complex float b)
+{
+  return (&b)[0];
+}
-- 
2.12.2

>From 097cdfb997ec6059947cab918197d9462897191e Mon Sep 17 00:00:00 2001
From: marxin <marxin@138bc75d-0d04-0410-961f-82ee72b054a4>
Date: Tue, 28 Mar 2017 11:37:22 +0000
Subject: [PATCH 02/12] Backport r246530

gcc/ChangeLog:

2017-03-28  Richard Biener  <rguent...@suse.de>

	PR ipa/80205
	* tree-inline.c (copy_phis_for_bb): Do not create PHI node
	without arguments, generate default definition of a SSA name.

gcc/testsuite/ChangeLog:

2017-03-28  Martin Liska  <mli...@suse.cz>

	PR ipa/80205
	* g++.dg/ipa/pr80205.C: New test.
---
 gcc/testsuite/g++.dg/ipa/pr80205.C | 34 ++++++++++++++
 gcc/tree-inline.c                  | 94 ++++++++++++++++++++------------------
 2 files changed, 84 insertions(+), 44 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/ipa/pr80205.C

diff --git a/gcc/testsuite/g++.dg/ipa/pr80205.C b/gcc/testsuite/g++.dg/ipa/pr80205.C
new file mode 100644
index 00000000000..460bdcb02ca
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ipa/pr80205.C
@@ -0,0 +1,34 @@
+// PR ipa/80205
+// { dg-options "-fnon-call-exceptions --param early-inlining-insns=100 -O2" }
+
+class a
+{
+public:
+  virtual ~a ();
+};
+class b
+{
+public:
+  template <typename c> b (c);
+  ~b () { delete d; }
+  void
+  operator= (b e)
+  {
+    b (e).f (*this);
+  }
+  void
+  f (b &e)
+  {
+    a g;
+    d = e.d;
+    e.d = &g;
+  }
+  a *d;
+};
+void
+h ()
+{
+  b i = int();
+  void j ();
+  i = j;
+}
diff --git a/gcc/tree-inline.c b/gcc/tree-inline.c
index e8c066015f5..60f79336cd7 100644
--- a/gcc/tree-inline.c
+++ b/gcc/tree-inline.c
@@ -2347,53 +2347,59 @@ copy_phis_for_bb (basic_block bb, copy_body_data *id)
 	{
 	  walk_tree (&new_res, copy_tree_body_r, id, NULL);
 	  new_phi = create_phi_node (new_res, new_bb);
-	  FOR_EACH_EDGE (new_edge, ei, new_bb->preds)
+	  if (EDGE_COUNT (new_bb->preds) == 0)
 	    {
-	      edge old_edge = find_edge ((basic_block) new_edge->src->aux, bb);
-	      tree arg;
-	      tree new_arg;
-	      edge_iterator ei2;
-	      location_t locus;
-
-	      /* When doing partial cloning, we allow PHIs on the entry block
-		 as long as all the arguments are the same.  Find any input
-		 edge to see argument to copy.  */
-	      if (!old_edge)
-		FOR_EACH_EDGE (old_edge, ei2, bb->preds)
-		  if (!old_edge->src->aux)
-		    break;
+	      /* Technically we'd want a SSA_DEFAULT_DEF here... */
+	      SSA_NAME_DEF_STMT (new_res) = gimple_build_nop ();
+	    }
+	  else
+	    FOR_EACH_EDGE (new_edge, ei, new_bb->preds)
+	      {
+		edge old_edge = find_edge ((basic_block) new_edge->src->aux, bb);
+		tree arg;
+		tree new_arg;
+		edge_iterator ei2;
+		location_t locus;
+
+		/* When doing partial cloning, we allow PHIs on the entry block
+		   as long as all the arguments are the same.  Find any input
+		   edge to see argument to copy.  */
+		if (!old_edge)
+		  FOR_EACH_EDGE (old_edge, ei2, bb->preds)
+		    if (!old_edge->src->aux)
+		      break;
 
-	      arg = PHI_ARG_DEF_FROM_EDGE (phi, old_edge);
-	      new_arg = arg;
-	      walk_tree (&new_arg, copy_tree_body_r, id, NULL);
-	      gcc_assert (new_arg);
-	      /* With return slot optimization we can end up with
-	         non-gimple (foo *)&this->m, fix that here.  */
-	      if (TREE_CODE (new_arg) != SSA_NAME
-		  && TREE_CODE (new_arg) != FUNCTION_DECL
-		  && !is_gimple_val (new_arg))
-		{
-		  gimple_seq stmts = NULL;
-		  new_arg = force_gimple_operand (new_arg, &stmts, true, NULL);
-		  gsi_insert_seq_on_edge (new_edge, stmts);
-		  inserted = true;
-		}
-	      locus = gimple_phi_arg_location_from_edge (phi, old_edge);
-	      if (LOCATION_BLOCK (locus))
-		{
-		  tree *n;
-		  n = id->decl_map->get (LOCATION_BLOCK (locus));
-		  gcc_assert (n);
-		  if (*n)
-		    locus = COMBINE_LOCATION_DATA (line_table, locus, *n);
-		  else
-		    locus = LOCATION_LOCUS (locus);
-		}
-	      else
-		locus = LOCATION_LOCUS (locus);
+		arg = PHI_ARG_DEF_FROM_EDGE (phi, old_edge);
+		new_arg = arg;
+		walk_tree (&new_arg, copy_tree_body_r, id, NULL);
+		gcc_assert (new_arg);
+		/* With return slot optimization we can end up with
+		   non-gimple (foo *)&this->m, fix that here.  */
+		if (TREE_CODE (new_arg) != SSA_NAME
+		    && TREE_CODE (new_arg) != FUNCTION_DECL
+		    && !is_gimple_val (new_arg))
+		  {
+		    gimple_seq stmts = NULL;
+		    new_arg = force_gimple_operand (new_arg, &stmts, true, NULL);
+		    gsi_insert_seq_on_edge (new_edge, stmts);
+		    inserted = true;
+		  }
+		locus = gimple_phi_arg_location_from_edge (phi, old_edge);
+		if (LOCATION_BLOCK (locus))
+		  {
+		    tree *n;
+		    n = id->decl_map->get (LOCATION_BLOCK (locus));
+		    gcc_assert (n);
+		    if (*n)
+		      locus = COMBINE_LOCATION_DATA (line_table, locus, *n);
+		    else
+		      locus = LOCATION_LOCUS (locus);
+		  }
+		 else
+		   locus = LOCATION_LOCUS (locus);
 
-	      add_phi_arg (new_phi, new_arg, new_edge, locus);
-	    }
+		add_phi_arg (new_phi, new_arg, new_edge, locus);
+	      }
 	}
     }
 
-- 
2.12.2

>From 7c08d4ef129b3602f3fe5e8fa16ba83fbea25386 Mon Sep 17 00:00:00 2001
From: marxin <marxin@138bc75d-0d04-0410-961f-82ee72b054a4>
Date: Thu, 6 Apr 2017 13:42:24 +0000
Subject: [PATCH 03/12] Backport r246730

gcc/testsuite/ChangeLog:

2017-04-06  Martin Liska  <mli...@suse.cz>

	PR sanitizer/80166
	* gcc.dg/asan/pr80166.c: New test.

libsanitizer/ChangeLog:

2017-04-06  Martin Liska  <mli...@suse.cz>

	PR sanitizer/80166
	* sanitizer_common/sanitizer_common_interceptors.inc (INTERCEPTOR):
	Cherry-pick upstream r299036.
---
 gcc/testsuite/gcc.dg/asan/pr80166.c                | 24 ++++++++++++++++++++++
 .../sanitizer_common_interceptors.inc              |  3 ++-
 2 files changed, 26 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.dg/asan/pr80166.c

diff --git a/gcc/testsuite/gcc.dg/asan/pr80166.c b/gcc/testsuite/gcc.dg/asan/pr80166.c
new file mode 100644
index 00000000000..629dd23a31c
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/asan/pr80166.c
@@ -0,0 +1,24 @@
+/* PR sanitizer/80166 */
+/* { dg-do run } */
+
+#include <sys/types.h>
+#include <unistd.h>
+
+int
+main (int argc, char **argv)
+{
+  gid_t groups;
+  int r = getgroups (0, &groups);
+  if (r < 0)
+    __builtin_abort ();
+
+  r = getgroups (-1, &groups);
+  if (r != -1)
+    __builtin_abort ();
+
+  r = getgroups (-1, NULL);
+  if (r != -1)
+    __builtin_abort ();
+
+  return 0;
+}
diff --git a/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc b/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc
index 10f321838e8..5a30498ff05 100644
--- a/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc
+++ b/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc
@@ -2733,7 +2733,8 @@ INTERCEPTOR(int, getgroups, int size, u32 *lst) {
   // its metadata. See
   // https://code.google.com/p/address-sanitizer/issues/detail?id=321.
   int res = REAL(getgroups)(size, lst);
-  if (res && lst) COMMON_INTERCEPTOR_WRITE_RANGE(ctx, lst, res * sizeof(*lst));
+  if (res >= 0 && lst && size > 0)
+    COMMON_INTERCEPTOR_WRITE_RANGE(ctx, lst, res * sizeof(*lst));
   return res;
 }
 #define INIT_GETGROUPS COMMON_INTERCEPT_FUNCTION(getgroups);
-- 
2.12.2

>From f378e2e4c85862618b6c4a1d787bd5e26d74baee Mon Sep 17 00:00:00 2001
From: marxin <marxin@138bc75d-0d04-0410-961f-82ee72b054a4>
Date: Mon, 10 Apr 2017 11:37:14 +0000
Subject: [PATCH 04/12] Backport r246804

gcc/ChangeLog:

2017-04-10  Martin Liska  <mli...@suse.cz>

	PR gcov-profile/80224
	* gcov.c (print_usage): Fix usage string.
	(get_gcov_intermediate_filename): Remove.
	(output_gcov_file): Use both for normal and intermediate format.
	(generate_results): Do not initialize special file for
	intermediate format.
---
 gcc/gcov.c | 63 +++++++-------------------------------------------------------
 1 file changed, 7 insertions(+), 56 deletions(-)

diff --git a/gcc/gcov.c b/gcc/gcov.c
index ea2dbf4315c..fd65efff94e 100644
--- a/gcc/gcov.c
+++ b/gcc/gcov.c
@@ -469,7 +469,7 @@ print_usage (int error_p)
   FILE *file = error_p ? stderr : stdout;
   int status = error_p ? FATAL_EXIT_CODE : SUCCESS_EXIT_CODE;
 
-  fnotice (file, "Usage: gcov [OPTION]... SOURCE|OBJ...\n\n");
+  fnotice (file, "Usage: gcov [OPTION...] SOURCE|OBJ...\n\n");
   fnotice (file, "Print code coverage information.\n\n");
   fnotice (file, "  -h, --help                      Print this help, then exit\n");
   fnotice (file, "  -a, --all-blocks                Show information for every basic block\n");
@@ -602,31 +602,6 @@ process_args (int argc, char **argv)
   return optind;
 }
 
-/* Get the name of the gcov file.  The return value must be free'd.
-
-   It appends the '.gcov' extension to the *basename* of the file.
-   The resulting file name will be in PWD.
-
-   e.g.,
-   input: foo.da,       output: foo.da.gcov
-   input: a/b/foo.cc,   output: foo.cc.gcov  */
-
-static char *
-get_gcov_intermediate_filename (const char *file_name)
-{
-  const char *gcov = ".gcov";
-  char *result;
-  const char *cptr;
-
-  /* Find the 'basename'.  */
-  cptr = lbasename (file_name);
-
-  result = XNEWVEC (char, strlen (cptr) + strlen (gcov) + 1);
-  sprintf (result, "%s%s", cptr, gcov);
-
-  return result;
-}
-
 /* Output the result in intermediate format used by 'lcov'.
 
 The intermediate format contains a single file named 'foo.cc.gcov',
@@ -792,7 +767,11 @@ output_gcov_file (const char *file_name, source_t *src)
       if (gcov_file)
         {
           fnotice (stdout, "Creating '%s'\n", gcov_file_name);
-          output_lines (gcov_file, src);
+
+	  if (flag_intermediate_format)
+	    output_intermediate_file (gcov_file, src);
+	  else
+	    output_lines (gcov_file, src);
           if (ferror (gcov_file))
             fnotice (stderr, "Error writing output file '%s'\n", gcov_file_name);
           fclose (gcov_file);
@@ -814,8 +793,6 @@ generate_results (const char *file_name)
   unsigned ix;
   source_t *src;
   function_t *fn;
-  FILE *gcov_intermediate_file = NULL;
-  char *gcov_intermediate_filename = NULL;
 
   for (ix = n_sources, src = sources; ix--; src++)
     if (src->num_lines)
@@ -845,20 +822,6 @@ generate_results (const char *file_name)
 	file_name = canonicalize_name (file_name);
     }
 
-  if (flag_gcov_file && flag_intermediate_format)
-    {
-      /* Open the intermediate file.  */
-      gcov_intermediate_filename =
-        get_gcov_intermediate_filename (file_name);
-      gcov_intermediate_file = fopen (gcov_intermediate_filename, "w");
-      if (!gcov_intermediate_file)
-        {
-          fnotice (stderr, "Cannot open intermediate output file %s\n",
-                   gcov_intermediate_filename);
-          return;
-        }
-    }
-
   for (ix = n_sources, src = sources; ix--; src++)
     {
       if (flag_relative_only)
@@ -881,23 +844,11 @@ generate_results (const char *file_name)
       total_executed += src->coverage.lines_executed;
       if (flag_gcov_file)
 	{
-          if (flag_intermediate_format)
-            /* Output the intermediate format without requiring source
-               files.  This outputs a section to a *single* file.  */
-            output_intermediate_file (gcov_intermediate_file, src);
-          else
-            output_gcov_file (file_name, src);
+	  output_gcov_file (file_name, src);
           fnotice (stdout, "\n");
         }
     }
 
-  if (flag_gcov_file && flag_intermediate_format)
-    {
-      /* Now we've finished writing the intermediate file.  */
-      fclose (gcov_intermediate_file);
-      XDELETEVEC (gcov_intermediate_filename);
-    }
-
   if (!file_name)
     executed_summary (total_lines, total_executed);
 }
-- 
2.12.2

>From ae9a787c54493c87dd8aefc5dfe2cfbcf617bc5f Mon Sep 17 00:00:00 2001
From: marxin <marxin@138bc75d-0d04-0410-961f-82ee72b054a4>
Date: Tue, 11 Apr 2017 13:08:08 +0000
Subject: [PATCH 05/12] Backport r246837

gcc/ChangeLog:

2017-04-11  Martin Liska  <mli...@suse.cz>

	PR sanitizer/70878
	* ubsan.c (instrument_object_size): Do not instrument register
	variables.

gcc/testsuite/ChangeLog:

2017-04-11  Martin Liska  <mli...@suse.cz>

	PR sanitizer/70878
	* gcc.dg/ubsan/pr70878.c: New test.
---
 gcc/testsuite/gcc.dg/ubsan/pr70878.c | 9 +++++++++
 gcc/ubsan.c                          | 6 +++++-
 2 files changed, 14 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.dg/ubsan/pr70878.c

diff --git a/gcc/testsuite/gcc.dg/ubsan/pr70878.c b/gcc/testsuite/gcc.dg/ubsan/pr70878.c
new file mode 100644
index 00000000000..acd7fb05e4c
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/ubsan/pr70878.c
@@ -0,0 +1,9 @@
+/* PR sanitizer/80878 */
+/* { dg-do compile { target { { i?86-*-* x86_64-*-* } && lp64 } } } */
+/* { dg-options "-fsanitize=object-size" } */
+
+void * sbrk ()
+{
+ volatile register unsigned int sp_r1 __asm__ ("ebx");
+ return __builtin_strcat ((char*)sp_r1, 0); /* { dg-warning "cast to pointer from integer of different size" } */
+}
diff --git a/gcc/ubsan.c b/gcc/ubsan.c
index c56864d54eb..ab563d7a921 100644
--- a/gcc/ubsan.c
+++ b/gcc/ubsan.c
@@ -1806,7 +1806,11 @@ instrument_object_size (gimple_stmt_iterator *gsi, bool is_lhs)
   bool decl_p = DECL_P (inner);
   tree base;
   if (decl_p)
-    base = inner;
+    {
+      if (DECL_REGISTER (inner))
+	return;
+      base = inner;
+    }
   else if (TREE_CODE (inner) == MEM_REF)
     base = TREE_OPERAND (inner, 0);
   else
-- 
2.12.2

>From 907fcce43322d8707388d3b7bd8d85923b0922a5 Mon Sep 17 00:00:00 2001
From: marxin <marxin@138bc75d-0d04-0410-961f-82ee72b054a4>
Date: Tue, 11 Apr 2017 16:37:31 +0000
Subject: [PATCH 06/12] Backport r246847

gcc/ChangeLog:

2017-04-11  Martin Liska  <mli...@suse.cz>

	PR ipa/80212
	* ipa-cp.c (determine_versionability): Handle calls_comdat_local
	flags.
---
 gcc/ipa-cp.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/gcc/ipa-cp.c b/gcc/ipa-cp.c
index 81a6ef8e066..adbd2ca4d34 100644
--- a/gcc/ipa-cp.c
+++ b/gcc/ipa-cp.c
@@ -514,6 +514,12 @@ determine_versionability (struct cgraph_node *node)
      decloned constructors, inlining is always better anyway.  */
   else if (node->comdat_local_p ())
     reason = "comdat-local function";
+  else if (node->calls_comdat_local)
+    {
+      /* TODO: call is versionable if we make sure that all
+	 callers are inside of a comdat group.  */
+      reason = "calls comdat-local function";
+    }
 
   if (reason && dump_file && !node->alias && !node->thunk.thunk_p)
     fprintf (dump_file, "Function %s/%i is not versionable, reason: %s.\n",
-- 
2.12.2

>From a581f3f01962982ac97d076943baf1ea60e7b7d2 Mon Sep 17 00:00:00 2001
From: marxin <marxin@138bc75d-0d04-0410-961f-82ee72b054a4>
Date: Tue, 11 Apr 2017 16:38:19 +0000
Subject: [PATCH 07/12] Backport r246848

gcc/ChangeLog:

2017-04-11  Martin Liska  <mli...@suse.cz>

	PR ipa/80212
	* cgraph.c (cgraph_node::dump): Dump calls_comdat_local.
	* ipa-split.c (split_function): Create a local comdat symbol
	if caller is in a comdat group.

gcc/testsuite/ChangeLog:

2017-04-11  Martin Liska  <mli...@suse.cz>

	PR ipa/80212
	* g++.dg/ipa/pr80212.C: New test.
---
 gcc/cgraph.c                       |  2 ++
 gcc/ipa-split.c                    |  9 +++++++++
 gcc/testsuite/g++.dg/ipa/pr80212.C | 18 ++++++++++++++++++
 3 files changed, 29 insertions(+)
 create mode 100644 gcc/testsuite/g++.dg/ipa/pr80212.C

diff --git a/gcc/cgraph.c b/gcc/cgraph.c
index 448e940586f..0fcd9364b18 100644
--- a/gcc/cgraph.c
+++ b/gcc/cgraph.c
@@ -2027,6 +2027,8 @@ cgraph_node::dump (FILE *f)
     fprintf (f, " only_called_at_exit");
   if (tm_clone)
     fprintf (f, " tm_clone");
+  if (calls_comdat_local)
+    fprintf (f, " calls_comdat_local");
   if (icf_merged)
     fprintf (f, " icf_merged");
   if (nonfreeing_fn)
diff --git a/gcc/ipa-split.c b/gcc/ipa-split.c
index b9678e11db0..c276b148859 100644
--- a/gcc/ipa-split.c
+++ b/gcc/ipa-split.c
@@ -1390,6 +1390,15 @@ split_function (basic_block return_bb, struct split_point *split_point,
 
   node->split_part = true;
 
+  if (cur_node->same_comdat_group)
+    {
+      /* TODO: call is versionable if we make sure that all
+	 callers are inside of a comdat group.  */
+      cur_node->calls_comdat_local = 1;
+      node->add_to_same_comdat_group (cur_node);
+    }
+
+
   /* Let's take a time profile for splitted function.  */
   node->tp_first_run = cur_node->tp_first_run + 1;
 
diff --git a/gcc/testsuite/g++.dg/ipa/pr80212.C b/gcc/testsuite/g++.dg/ipa/pr80212.C
new file mode 100644
index 00000000000..60d3b613035
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ipa/pr80212.C
@@ -0,0 +1,18 @@
+// PR ipa/80212
+// { dg-options "-O2 --param partial-inlining-entry-probability=403796683 -fno-early-inlining" }
+
+struct b
+{
+  virtual b *c () const;
+};
+struct d : virtual b
+{
+};
+struct e : d
+{
+  e *
+  c () const
+  {
+  }
+};
+main () { e a; }
-- 
2.12.2

>From de331ea39ed90f3ca4147c38ffb4511bdb6a2895 Mon Sep 17 00:00:00 2001
From: marxin <marxin@138bc75d-0d04-0410-961f-82ee72b054a4>
Date: Thu, 13 Apr 2017 11:51:28 +0000
Subject: [PATCH 08/12] Backport r246903

gcc/ChangeLog:

2017-04-13  Martin Liska  <mli...@suse.cz>

	PR gcov-profile/80413
	* gcov-io.c (gcov_write_string): Copy to buffer just when
	allocated size is greater than zero.
---
 gcc/gcov-io.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/gcc/gcov-io.c b/gcc/gcov-io.c
index cbd0a9f1471..9044aec6fe6 100644
--- a/gcc/gcov-io.c
+++ b/gcc/gcov-io.c
@@ -372,8 +372,12 @@ gcov_write_string (const char *string)
   buffer = gcov_write_words (1 + alloc);
 
   buffer[0] = alloc;
-  buffer[alloc] = 0;
-  memcpy (&buffer[1], string, length);
+
+  if (alloc > 0)
+    {
+      buffer[alloc] = 0; /* place nul terminators.  */
+      memcpy (&buffer[1], string, length);
+    }
 }
 #endif
 
-- 
2.12.2

>From 22cef60ae8c9d65dc3ef307f17e46e5bb7a6b86a Mon Sep 17 00:00:00 2001
From: marxin <marxin@138bc75d-0d04-0410-961f-82ee72b054a4>
Date: Tue, 18 Apr 2017 07:24:20 +0000
Subject: [PATCH 09/12] Backport r246961

gcc/ChangeLog:

2017-04-18  Martin Liska  <mli...@suse.cz>

	PR gcov-profile/78783
	* gcov-tool.c (gcov_output_files): Validate that destination
	file is either removed by the tool or by a user.

libgcc/ChangeLog:

2017-04-18  Martin Liska  <mli...@suse.cz>

	PR gcov-profile/78783
	* libgcov-driver.c (gcov_get_filename): New function.
---
 gcc/gcov-tool.c         | 9 +++++++++
 libgcc/libgcov-driver.c | 9 +++++++++
 2 files changed, 18 insertions(+)

diff --git a/gcc/gcov-tool.c b/gcc/gcov-tool.c
index fd27d7c11ad..3a8dfc1ca8b 100644
--- a/gcc/gcov-tool.c
+++ b/gcc/gcov-tool.c
@@ -46,6 +46,7 @@ extern int gcov_profile_normalize (struct gcov_info*, gcov_type);
 extern int gcov_profile_scale (struct gcov_info*, float, int, int);
 extern struct gcov_info* gcov_read_profile_dir (const char*, int);
 extern void gcov_do_dump (struct gcov_info *, int);
+extern const char *gcov_get_filename (struct gcov_info *list);
 extern void gcov_set_verbose (void);
 
 /* Set to verbose output mode.  */
@@ -114,6 +115,14 @@ gcov_output_files (const char *out, struct gcov_info *profile)
   if (ret)
     fatal_error (input_location, "Cannot change directory to %s", out);
 
+  /* Verify that output file does not exist (either was removed by
+     unlink_profile_data or removed by user).  */
+  const char *filename = gcov_get_filename (profile);
+
+  if (access (filename, F_OK) != -1)
+    fatal_error (input_location, "output file %s already exists in folder %s",
+		 filename, out);
+
   gcov_do_dump (profile, 0);
 
   ret = chdir (pwd);
diff --git a/libgcc/libgcov-driver.c b/libgcc/libgcov-driver.c
index 221ac0c00d0..4886c5d100f 100644
--- a/libgcc/libgcov-driver.c
+++ b/libgcc/libgcov-driver.c
@@ -848,6 +848,15 @@ gcov_do_dump (struct gcov_info *list, int run_counted)
   free (gf.filename);
 }
 
+#if IN_GCOV_TOOL
+const char *
+__attribute__ ((unused))
+gcov_get_filename (struct gcov_info *list)
+{
+  return list->filename;
+}
+#endif
+
 #if !IN_GCOV_TOOL
 void
 __gcov_dump_one (struct gcov_root *root)
-- 
2.12.2

>From 8bfd13657455abd74066fcbb484b21a457afb86e Mon Sep 17 00:00:00 2001
From: marxin <marxin@138bc75d-0d04-0410-961f-82ee72b054a4>
Date: Wed, 19 Apr 2017 12:00:47 +0000
Subject: [PATCH 10/12] Backport r246995

gcc/ChangeLog:

2017-04-19  Paulo J. Matos  <pa...@matos-sorge.com>

	PR lto/50345
	* doc/lto.texi: Remove an extra 'that'.
---
 gcc/doc/lto.texi | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/doc/lto.texi b/gcc/doc/lto.texi
index 41fd97223ac..25d9cc15ee0 100644
--- a/gcc/doc/lto.texi
+++ b/gcc/doc/lto.texi
@@ -43,7 +43,7 @@ existing build systems, as one can, for instance, produce archives of
 the files.  Additionally, one might be able to ship one set of fat
 objects which could be used both for development and the production of
 optimized builds.  A, perhaps surprising, side effect of this feature
-is that any mistake in the toolchain that leads to LTO information not
+is that any mistake in the toolchain leads to LTO information not
 being used (e.g.@: an older @code{libtool} calling @code{ld} directly).
 This is both an advantage, as the system is more robust, and a
 disadvantage, as the user is not informed that the optimization has
-- 
2.12.2

>From 9d3c7da2a86de15f7c9bb871e2e63dd64090fa68 Mon Sep 17 00:00:00 2001
From: marxin <marxin@138bc75d-0d04-0410-961f-82ee72b054a4>
Date: Wed, 19 Apr 2017 12:06:35 +0000
Subject: [PATCH 11/12] Backport r246996

gcc/ChangeLog:

2017-04-19  Richard Biener  <rguent...@suse.de>

	PR ipa/65972
	* auto-profile.c (afdo_vpt_for_early_inline): Update SSA
	when needed by AutoPGO.
---
 gcc/auto-profile.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/gcc/auto-profile.c b/gcc/auto-profile.c
index ba2d5ab654e..5e212dd0579 100644
--- a/gcc/auto-profile.c
+++ b/gcc/auto-profile.c
@@ -1469,7 +1469,9 @@ afdo_vpt_for_early_inline (stmt_set *promoted_stmts)
 
   if (has_vpt)
     {
-      optimize_inline_calls (current_function_decl);
+      unsigned todo = optimize_inline_calls (current_function_decl);
+      if (todo & TODO_update_ssa_any)
+       update_ssa (TODO_update_ssa);
       return true;
     }
 
-- 
2.12.2

>From df314687531986d3a06b309e226a1e5fc7cdfc01 Mon Sep 17 00:00:00 2001
From: marxin <marxin@138bc75d-0d04-0410-961f-82ee72b054a4>
Date: Mon, 24 Apr 2017 13:16:34 +0000
Subject: [PATCH 12/12] Backport r247097

gcc/ChangeLog:

2017-04-24  Jan Hubicka  <hubi...@ucw.cz>

	PR middle-end/79931
	* ipa-devirt.c (dump_possible_polymorphic_call_targets): Fix ICE.

gcc/testsuite/ChangeLog:

2017-04-24  Martin Liska  <mli...@suse.cz>

	PR middle-end/79931
	* g++.dg/ipa/pr79931.C: New test.
---
 gcc/ipa-devirt.c                   |  8 +++++++-
 gcc/testsuite/g++.dg/ipa/pr79931.C | 24 ++++++++++++++++++++++++
 2 files changed, 31 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.dg/ipa/pr79931.C

diff --git a/gcc/ipa-devirt.c b/gcc/ipa-devirt.c
index c165bceb16b..08cfa8033f0 100644
--- a/gcc/ipa-devirt.c
+++ b/gcc/ipa-devirt.c
@@ -3211,7 +3211,13 @@ dump_possible_polymorphic_call_targets (FILE *f,
       fprintf (f, "  Speculative targets:");
       dump_targets (f, targets);
     }
-  gcc_assert (targets.length () <= len);
+  /* Ugly: during callgraph construction the target cache may get populated
+     before all targets are found.  While this is harmless (because all local
+     types are discovered and only in those case we devirtualize fully and we
+     don't do speculative devirtualization before IPA stage) it triggers
+     assert here when dumping at that stage also populates the case with
+     speculative targets.  Quietly ignore this.  */
+  gcc_assert (symtab->state < IPA_SSA || targets.length () <= len);
   fprintf (f, "\n");
 }
 
diff --git a/gcc/testsuite/g++.dg/ipa/pr79931.C b/gcc/testsuite/g++.dg/ipa/pr79931.C
new file mode 100644
index 00000000000..78f6e03c458
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ipa/pr79931.C
@@ -0,0 +1,24 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-ipa-all" } */
+
+class DocumentImpl;
+struct NodeImpl
+{
+  virtual DocumentImpl * getOwnerDocument();
+  virtual NodeImpl * getParentNode();
+  virtual NodeImpl * removeChild(NodeImpl *oldChild);
+};
+struct AttrImpl : NodeImpl
+{
+  NodeImpl *insertBefore(NodeImpl *newChild, NodeImpl *refChild);
+};
+struct DocumentImpl : NodeImpl
+{
+  virtual NodeImpl *removeChild(NodeImpl *oldChild);
+  virtual int* getRanges();
+};
+NodeImpl *AttrImpl::insertBefore(NodeImpl *newChild, NodeImpl *refChild) {
+  NodeImpl *oldparent = newChild->getParentNode();
+  oldparent->removeChild(newChild);
+  this->getOwnerDocument()->getRanges();
+}
-- 
2.12.2

Reply via email to