public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Backport to GCC5
@ 2017-05-29 10:04 Martin Liška
  0 siblings, 0 replies; 2+ messages in thread
From: Martin Liška @ 2017-05-29 10:04 UTC (permalink / raw)
  To: GCC Patches

[-- Attachment #1: Type: text/plain, Size: 160 bytes --]

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


[-- Attachment #2: 0001-Backport-r246525.patch --]
[-- Type: text/x-patch, Size: 1661 bytes --]

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  <mliska@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  <mliska@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


[-- Attachment #3: 0002-Backport-r246530.patch --]
[-- Type: text/x-patch, Size: 4955 bytes --]

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  <rguenther@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  <mliska@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


[-- Attachment #4: 0003-Backport-r246730.patch --]
[-- Type: text/x-patch, Size: 2184 bytes --]

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  <mliska@suse.cz>

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

libsanitizer/ChangeLog:

2017-04-06  Martin Liska  <mliska@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


[-- Attachment #5: 0004-Backport-r246804.patch --]
[-- Type: text/x-patch, Size: 4448 bytes --]

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  <mliska@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


[-- Attachment #6: 0005-Backport-r246837.patch --]
[-- Type: text/x-patch, Size: 1719 bytes --]

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  <mliska@suse.cz>

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

gcc/testsuite/ChangeLog:

2017-04-11  Martin Liska  <mliska@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


[-- Attachment #7: 0006-Backport-r246847.patch --]
[-- Type: text/x-patch, Size: 1117 bytes --]

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  <mliska@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


[-- Attachment #8: 0007-Backport-r246848.patch --]
[-- Type: text/x-patch, Size: 2305 bytes --]

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  <mliska@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  <mliska@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


[-- Attachment #9: 0008-Backport-r246903.patch --]
[-- Type: text/x-patch, Size: 939 bytes --]

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  <mliska@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


[-- Attachment #10: 0009-Backport-r246961.patch --]
[-- Type: text/x-patch, Size: 2236 bytes --]

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  <mliska@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  <mliska@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


[-- Attachment #11: 0010-Backport-r246995.patch --]
[-- Type: text/x-patch, Size: 1199 bytes --]

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  <paulo@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


[-- Attachment #12: 0011-Backport-r246996.patch --]
[-- Type: text/x-patch, Size: 936 bytes --]

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  <rguenther@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


[-- Attachment #13: 0012-Backport-r247097.patch --]
[-- Type: text/x-patch, Size: 2485 bytes --]

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  <hubicka@ucw.cz>

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

gcc/testsuite/ChangeLog:

2017-04-24  Martin Liska  <mliska@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


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Backport to GCC5
  2017-03-22 10:15 Backport to GCC6 Martin Liška
@ 2017-03-22 12:22 ` Martin Liška
  0 siblings, 0 replies; 2+ messages in thread
From: Martin Liška @ 2017-03-22 12:22 UTC (permalink / raw)
  To: GCC Patches

[-- Attachment #1: Type: text/plain, Size: 278 bytes --]

Hello.

This is very same series as the one for GCC6. Only exception is toplev.c, which is
squashed just to a single patch. And a multi-versioning patch is omitted.

Patch can bootstrap on x86_64-linux-gnu and survives regression tests.

I'm going to install the series.
Martin

[-- Attachment #2: 0001-Backport-r245532.patch --]
[-- Type: text/x-patch, Size: 901 bytes --]

From 62b6cbefcf9eba678d77aa6e979b3f0c6a3f6b79 Mon Sep 17 00:00:00 2001
From: marxin <marxin@138bc75d-0d04-0410-961f-82ee72b054a4>
Date: Fri, 17 Feb 2017 14:47:08 +0000
Subject: [PATCH 01/15] Backport r245532

gcc/ChangeLog:

2017-02-17  Martin Liska  <mliska@suse.cz>

	PR rtl-optimization/79577
	* params.def (selsched-max-sched-times): Increase minimum to 1.
---
 gcc/params.def | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/params.def b/gcc/params.def
index 48b39a25041..33d637675ab 100644
--- a/gcc/params.def
+++ b/gcc/params.def
@@ -656,7 +656,7 @@ DEFPARAM(PARAM_SELSCHED_MAX_LOOKAHEAD,
 DEFPARAM(PARAM_SELSCHED_MAX_SCHED_TIMES,
          "selsched-max-sched-times",
          "Maximum number of times that an insn could be scheduled",
-         2, 0, 0)
+         2, 1, 0)
 
 DEFPARAM(PARAM_SELSCHED_INSNS_TO_RENAME,
          "selsched-insns-to-rename",
-- 
2.12.0


[-- Attachment #3: 0002-Backport-r245531.patch --]
[-- Type: text/x-patch, Size: 1810 bytes --]

From 3005209ed0529e7cefed1fdb27c76e9c6c001a9d Mon Sep 17 00:00:00 2001
From: marxin <marxin@138bc75d-0d04-0410-961f-82ee72b054a4>
Date: Fri, 17 Feb 2017 14:46:14 +0000
Subject: [PATCH 02/15] Backport r245531

gcc/ChangeLog:

2017-02-17  Martin Liska  <mliska@suse.cz>

	PR rtl-optimization/79574
	* gcse.c (want_to_gcse_p): Prevent integer overflow.

gcc/testsuite/ChangeLog:

2017-02-17  Martin Liska  <mliska@suse.cz>

	PR rtl-optimization/79574
	* gcc.dg/pr79574.c: New test.
---
 gcc/gcse.c                     |  5 +++--
 gcc/testsuite/gcc.dg/pr79574.c | 10 ++++++++++
 2 files changed, 13 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/pr79574.c

diff --git a/gcc/gcse.c b/gcc/gcse.c
index 0f6d456ab39..c6bea33c6d2 100644
--- a/gcc/gcse.c
+++ b/gcc/gcse.c
@@ -824,7 +824,7 @@ want_to_gcse_p (rtx x, int *max_distance_ptr)
 	/* PRE doesn't implement max_distance restriction.  */
 	{
 	  int cost;
-	  int max_distance;
+	  HOST_WIDE_INT max_distance;
 
 	  gcc_assert (!optimize_function_for_speed_p (cfun)
 		      && optimize_function_for_size_p (cfun));
@@ -832,7 +832,8 @@ want_to_gcse_p (rtx x, int *max_distance_ptr)
 
 	  if (cost < COSTS_N_INSNS (GCSE_UNRESTRICTED_COST))
 	    {
-	      max_distance = (GCSE_COST_DISTANCE_RATIO * cost) / 10;
+	      max_distance
+		= ((HOST_WIDE_INT)GCSE_COST_DISTANCE_RATIO * cost) / 10;
 	      if (max_distance == 0)
 		return 0;
 
diff --git a/gcc/testsuite/gcc.dg/pr79574.c b/gcc/testsuite/gcc.dg/pr79574.c
new file mode 100644
index 00000000000..1b666e20d21
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr79574.c
@@ -0,0 +1,10 @@
+/* PR rtl-optimization/79574 */
+/* { dg-do compile } */
+/* { dg-options "-Os --param gcse-cost-distance-ratio=2147483647" } */
+
+void a (void)
+{
+  volatile int b;
+  for (;; b)
+    ;
+}
-- 
2.12.0


[-- Attachment #4: 0003-Backport-r245868.patch --]
[-- Type: text/x-patch, Size: 6001 bytes --]

From 895302c15bcfefca67a3c9f6a9802112ca1b2b12 Mon Sep 17 00:00:00 2001
From: marxin <marxin@138bc75d-0d04-0410-961f-82ee72b054a4>
Date: Fri, 3 Mar 2017 11:53:14 +0000
Subject: [PATCH 03/15] Backport r245868

gcc/ChangeLog:

2017-03-03  Martin Liska  <mliska@suse.cz>

	PR rtl-optimization/79574
	* gcse.c (struct gcse_expr): Use HOST_WIDE_INT instead of int.
	(hash_scan_set): Likewise.
	(dump_hash_table): Likewise.
	(hoist_code): Likewise.

gcc/testsuite/ChangeLog:

2017-03-03  Martin Liska  <mliska@suse.cz>

	PR rtl-optimization/79574
	* gcc.dg/pr79574-2.c: New test.
---
 gcc/gcse.c                       | 29 +++++++++++++++++------------
 gcc/testsuite/gcc.dg/pr79574-2.c | 33 +++++++++++++++++++++++++++++++++
 2 files changed, 50 insertions(+), 12 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/pr79574-2.c

diff --git a/gcc/gcse.c b/gcc/gcse.c
index c6bea33c6d2..394620d64f6 100644
--- a/gcc/gcse.c
+++ b/gcc/gcse.c
@@ -311,7 +311,7 @@ struct gcse_expr
      to keep register pressure under control.
      A value of "0" removes restrictions on how far the expression can
      travel.  */
-  int max_distance;
+  HOST_WIDE_INT max_distance;
 };
 
 /* Occurrence of an expression.
@@ -486,12 +486,12 @@ static void hash_scan_insn (rtx_insn *, struct gcse_hash_table_d *);
 static void hash_scan_set (rtx, rtx_insn *, struct gcse_hash_table_d *);
 static void hash_scan_clobber (rtx, rtx_insn *, struct gcse_hash_table_d *);
 static void hash_scan_call (rtx, rtx_insn *, struct gcse_hash_table_d *);
-static int want_to_gcse_p (rtx, int *);
+static int want_to_gcse_p (rtx, HOST_WIDE_INT *);
 static int oprs_unchanged_p (const_rtx, const rtx_insn *, int);
 static int oprs_anticipatable_p (const_rtx, const rtx_insn *);
 static int oprs_available_p (const_rtx, const rtx_insn *);
 static void insert_expr_in_table (rtx, machine_mode, rtx_insn *, int, int,
-				  int, struct gcse_hash_table_d *);
+				  HOST_WIDE_INT, struct gcse_hash_table_d *);
 static unsigned int hash_expr (const_rtx, machine_mode, int *, int);
 static void record_last_reg_set_info (rtx, int);
 static void record_last_mem_set_info (rtx_insn *);
@@ -521,8 +521,10 @@ static void alloc_code_hoist_mem (int, int);
 static void free_code_hoist_mem (void);
 static void compute_code_hoist_vbeinout (void);
 static void compute_code_hoist_data (void);
-static int should_hoist_expr_to_dom (basic_block, struct gcse_expr *, basic_block,
-				     sbitmap, int, int *, enum reg_class,
+static int should_hoist_expr_to_dom (basic_block, struct gcse_expr *,
+				     basic_block,
+				     sbitmap, HOST_WIDE_INT, int *,
+				     enum reg_class,
 				     int *, bitmap, rtx_insn *);
 static int hoist_code (void);
 static enum reg_class get_regno_pressure_class (int regno, int *nregs);
@@ -777,7 +779,7 @@ static basic_block current_bb;
    GCSE.  */
 
 static int
-want_to_gcse_p (rtx x, int *max_distance_ptr)
+want_to_gcse_p (rtx x, HOST_WIDE_INT *max_distance_ptr)
 {
 #ifdef STACK_REGS
   /* On register stack architectures, don't GCSE constants from the
@@ -1150,7 +1152,8 @@ expr_equiv_p (const_rtx x, const_rtx y)
 static void
 insert_expr_in_table (rtx x, machine_mode mode, rtx_insn *insn,
 		      int antic_p,
-		      int avail_p, int max_distance, struct gcse_hash_table_d *table)
+		      int avail_p, HOST_WIDE_INT max_distance,
+		      struct gcse_hash_table_d *table)
 {
   int found, do_not_record_p;
   unsigned int hash;
@@ -1266,7 +1269,7 @@ hash_scan_set (rtx set, rtx_insn *insn, struct gcse_hash_table_d *table)
   else if (REG_P (dest))
     {
       unsigned int regno = REGNO (dest);
-      int max_distance = 0;
+      HOST_WIDE_INT max_distance = 0;
 
       /* See if a REG_EQUAL note shows this equivalent to a simpler expression.
 
@@ -1335,7 +1338,7 @@ hash_scan_set (rtx set, rtx_insn *insn, struct gcse_hash_table_d *table)
   else if (flag_gcse_las && REG_P (src) && MEM_P (dest))
       {
         unsigned int regno = REGNO (src);
-	int max_distance = 0;
+	HOST_WIDE_INT max_distance = 0;
 
 	/* Only record sets of pseudo-regs in the hash table.  */
         if (regno >= FIRST_PSEUDO_REGISTER
@@ -1448,7 +1451,8 @@ dump_hash_table (FILE *file, const char *name, struct gcse_hash_table_d *table)
     if (flat_table[i] != 0)
       {
 	expr = flat_table[i];
-	fprintf (file, "Index %d (hash value %d; max distance %d)\n  ",
+	fprintf (file, "Index %d (hash value %d; max distance "
+		 HOST_WIDE_INT_PRINT_DEC ")\n  ",
 		 expr->bitmap_index, hash_val[i], expr->max_distance);
 	print_rtl (file, expr->expr);
 	fprintf (file, "\n");
@@ -2909,7 +2913,8 @@ update_bb_reg_pressure (basic_block bb, rtx_insn *from)
 
 static int
 should_hoist_expr_to_dom (basic_block expr_bb, struct gcse_expr *expr,
-			  basic_block bb, sbitmap visited, int distance,
+			  basic_block bb, sbitmap visited,
+			  HOST_WIDE_INT distance,
 			  int *bb_size, enum reg_class pressure_class,
 			  int *nregs, bitmap hoisted_bbs, rtx_insn *from)
 {
@@ -3186,7 +3191,7 @@ hoist_code (void)
 		 computes the expression.  */
 	      FOR_EACH_VEC_ELT (domby, j, dominated)
 		{
-		  int max_distance;
+		  HOST_WIDE_INT max_distance;
 
 		  /* Ignore self dominance.  */
 		  if (bb == dominated)
diff --git a/gcc/testsuite/gcc.dg/pr79574-2.c b/gcc/testsuite/gcc.dg/pr79574-2.c
new file mode 100644
index 00000000000..995dff40174
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr79574-2.c
@@ -0,0 +1,33 @@
+/* PR rtl-optimization/79574 */
+/* { dg-do compile } */
+/* { dg-options "-Os --param gcse-cost-distance-ratio=2147483647" } */
+
+#include "stdarg.h"
+
+int buf[100];
+int buf1[10];
+
+int rd (int *pppp, int n, ...)
+{
+  va_list argp;
+  int *p;
+  int i;
+  int res;
+
+  va_start (argp, n);
+  for (; n > 0; n--)
+    va_arg (argp, double);
+  p = va_arg (argp, int *);
+  i = va_arg (argp, int);
+
+  res = p[i];
+  __builtin_printf ("%d\n", res);
+
+  return res;
+}
+
+int mpx_test (int argc, const char **argv)
+{
+  rd (buf1, 2, 10.0d, 10.0d, buf, 100, buf1);
+  return 0;
+}
-- 
2.12.0


[-- Attachment #5: 0004-Backport-r245869.patch --]
[-- Type: text/x-patch, Size: 3330 bytes --]

From be291d46722aab9978ad041c1868521c5ddf5d8a Mon Sep 17 00:00:00 2001
From: marxin <marxin@138bc75d-0d04-0410-961f-82ee72b054a4>
Date: Fri, 3 Mar 2017 11:53:56 +0000
Subject: [PATCH 04/15] Backport r245869

gcc/ChangeLog:

2017-03-03  Martin Liska  <mliska@suse.cz>

	PR tree-optimization/79803
	* tree-ssa-loop-prefetch.c (tree_ssa_prefetch_arrays): Remove
	assert.
	(pass_loop_prefetch::execute): Disabled optimization if an
	assumption about L1 cache size is not met.

gcc/testsuite/ChangeLog:

2017-03-03  Martin Liska  <mliska@suse.cz>

	PR tree-optimization/79803
	* gcc.dg/tree-ssa/pr79803.c: New test.
---
 gcc/testsuite/gcc.dg/tree-ssa/pr79803.c | 60 +++++++++++++++++++++++++++++++++
 gcc/tree-ssa-loop-prefetch.c            | 19 ++++++++---
 2 files changed, 75 insertions(+), 4 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr79803.c

diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr79803.c b/gcc/testsuite/gcc.dg/tree-ssa/pr79803.c
new file mode 100644
index 00000000000..51b245d4d5b
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr79803.c
@@ -0,0 +1,60 @@
+/* { dg-do compile { target { x86_64-*-* } } } */
+/* { dg-options "-march=opteron-sse3 -Ofast --param l1-cache-line-size=3 -Wdisabled-optimization" } */
+/* { dg-require-effective-target indirect_jumps } */
+
+#include <setjmp.h>
+
+extern void abort (void);
+
+jmp_buf buf;
+
+void raise0(void)
+{
+  __builtin_longjmp (buf, 1);
+}
+
+int execute(int cmd) /* { dg-warning "'l1-cache-size' parameter is not a power of two 3" } */
+{
+  int last = 0;
+
+  if (__builtin_setjmp (buf) == 0)
+    while (1)
+      {
+	last = 1;
+	raise0 ();
+      }
+
+  if (last == 0)
+    return 0;
+  else
+    return cmd;
+}
+
+int execute2(int cmd, int cmd2)
+{
+  int last = 0;
+
+  if (__builtin_setjmp (buf) == 0)
+    while (1)
+      {
+	last = 1;
+	raise0 ();
+      }
+
+  if (last == 0)
+    return 0;
+  else
+    return cmd;
+}
+
+
+int main(void)
+{
+  if (execute (1) == 0)
+    abort ();
+
+  if (execute2 (1, 2) == 0)
+    abort ();
+
+  return 0;
+}
diff --git a/gcc/tree-ssa-loop-prefetch.c b/gcc/tree-ssa-loop-prefetch.c
index 10e156e997f..a007f726cbc 100644
--- a/gcc/tree-ssa-loop-prefetch.c
+++ b/gcc/tree-ssa-loop-prefetch.c
@@ -65,6 +65,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "langhooks.h"
 #include "tree-inline.h"
 #include "tree-data-ref.h"
+#include "diagnostic-core.h"
 
 
 /* FIXME: Needed for optabs, but this should all be moved to a TBD interface
@@ -2005,10 +2006,6 @@ tree_ssa_prefetch_arrays (void)
       set_builtin_decl (BUILT_IN_PREFETCH, decl, false);
     }
 
-  /* We assume that size of cache line is a power of two, so verify this
-     here.  */
-  gcc_assert ((PREFETCH_BLOCK & (PREFETCH_BLOCK - 1)) == 0);
-
   FOR_EACH_LOOP (loop, LI_FROM_INNERMOST)
     {
       if (dump_file && (dump_flags & TDF_DETAILS))
@@ -2066,6 +2063,20 @@ pass_loop_prefetch::execute (function *fun)
   if (number_of_loops (fun) <= 1)
     return 0;
 
+  if ((PREFETCH_BLOCK & (PREFETCH_BLOCK - 1)) != 0)
+    {
+      static bool warned = false;
+
+      if (!warned)
+	{
+	  warning (OPT_Wdisabled_optimization,
+		   "%<l1-cache-size%> parameter is not a power of two %d",
+		   PREFETCH_BLOCK);
+	  warned = true;
+	}
+      return 0;
+    }
+
   return tree_ssa_prefetch_arrays ();
 }
 
-- 
2.12.0


[-- Attachment #6: 0005-Backport-r245992.patch --]
[-- Type: text/x-patch, Size: 870 bytes --]

From 7a120621efda943b27748276f1f01d81057692a6 Mon Sep 17 00:00:00 2001
From: marxin <marxin@138bc75d-0d04-0410-961f-82ee72b054a4>
Date: Thu, 9 Mar 2017 09:20:59 +0000
Subject: [PATCH 05/15] Backport r245992

gcc/c-family/ChangeLog:

2017-03-09  Martin Liska  <mliska@suse.cz>

	* c-ada-spec.c (macro_length): Increment value instead of a pointer.
---
 gcc/c-family/c-ada-spec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/c-family/c-ada-spec.c b/gcc/c-family/c-ada-spec.c
index 8d6e01421cd..2814be426db 100644
--- a/gcc/c-family/c-ada-spec.c
+++ b/gcc/c-family/c-ada-spec.c
@@ -85,7 +85,7 @@ macro_length (const cpp_macro *macro, int *supported, int *buffer_len,
 
   if (macro->fun_like)
     {
-      param_len++;
+      (*param_len)++;
       for (i = 0; i < macro->paramc; i++)
 	{
 	  cpp_hashnode *param = macro->params[i];
-- 
2.12.0


[-- Attachment #7: 0006-Backport-r245993.patch --]
[-- Type: text/x-patch, Size: 1942 bytes --]

From 37ea6d19212a188080081d0e087882693bdc75c1 Mon Sep 17 00:00:00 2001
From: marxin <marxin@138bc75d-0d04-0410-961f-82ee72b054a4>
Date: Thu, 9 Mar 2017 09:22:29 +0000
Subject: [PATCH 06/15] Backport r245993

gcc/ChangeLog:

2017-03-09  Martin Liska  <mliska@suse.cz>

	PR ipa/79761
	* tree-chkp.c (chkp_get_bound_for_parm): Get bounds for a param.
	(chkp_find_bounds_1): Remove gcc_unreachable.

gcc/testsuite/ChangeLog:

2017-03-09  Martin Liska  <mliska@suse.cz>

	PR ipa/79761
	* g++.dg/pr79761.C: New test.
---
 gcc/testsuite/g++.dg/pr79761.C | 34 ++++++++++++++++++++++++++++++++++
 gcc/tree-chkp.c                |  4 ++--
 2 files changed, 36 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/pr79761.C

diff --git a/gcc/testsuite/g++.dg/pr79761.C b/gcc/testsuite/g++.dg/pr79761.C
new file mode 100644
index 00000000000..a97325a1fc4
--- /dev/null
+++ b/gcc/testsuite/g++.dg/pr79761.C
@@ -0,0 +1,34 @@
+/* { dg-do compile { target { { i?86-*-* x86_64-*-* } && { ! x32 } } } } */
+/* { dg-options "-fcheck-pointer-bounds -mmpx -mabi=ms" } */
+
+struct Foo
+{
+  Foo() : a(1), b(1), c('a') {}
+  int a;
+  int b;
+  char c;
+};
+
+static Foo copy_foo(Foo) __attribute__((noinline, noclone));
+
+static Foo copy_foo(Foo A)
+{
+  return A;
+}
+
+struct Bar : Foo
+{
+  Bar(Foo t) : Foo(copy_foo(t)) {}
+};
+
+Foo F;
+
+int main (void)
+{
+  Bar B (F);
+
+  if (B.a != 1 || B.b != 1 || B.c != 'a')
+    __builtin_abort ();
+
+  return 0;
+}
diff --git a/gcc/tree-chkp.c b/gcc/tree-chkp.c
index 218c7eb40ab..237399ecc96 100644
--- a/gcc/tree-chkp.c
+++ b/gcc/tree-chkp.c
@@ -3556,8 +3556,8 @@ chkp_find_bounds_1 (tree ptr, tree ptr_src, gimple_stmt_iterator *iter)
       break;
 
     case PARM_DECL:
-      gcc_unreachable ();
-      bounds = chkp_get_bound_for_parm (ptr_src);
+      /* Handled above but failed.  */
+      bounds = chkp_get_invalid_op_bounds ();
       break;
 
     case TARGET_MEM_REF:
-- 
2.12.0


[-- Attachment #8: 0007-Backport-r245998.patch --]
[-- Type: text/x-patch, Size: 1973 bytes --]

From e268aa788c0c69f2015d124b8e2270e478a31d30 Mon Sep 17 00:00:00 2001
From: marxin <marxin@138bc75d-0d04-0410-961f-82ee72b054a4>
Date: Thu, 9 Mar 2017 10:10:02 +0000
Subject: [PATCH 07/15] Backport r245998

gcc/ChangeLog:

2017-03-09  Martin Liska  <mliska@suse.cz>

	PR tree-optimization/79631
	* tree-chkp-opt.c (chkp_is_constant_addr): Call
	tree_int_cst_sign_bit just for INTEGER constants.

gcc/testsuite/ChangeLog:

2017-03-09  Martin Liska  <mliska@suse.cz>

	PR tree-optimization/79631
	* gcc.target/i386/mpx/pr79631.c: New test.
---
 gcc/testsuite/gcc.target/i386/mpx/pr79631.c | 15 +++++++++++++++
 gcc/tree-chkp-opt.c                         |  4 +++-
 2 files changed, 18 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.target/i386/mpx/pr79631.c

diff --git a/gcc/testsuite/gcc.target/i386/mpx/pr79631.c b/gcc/testsuite/gcc.target/i386/mpx/pr79631.c
new file mode 100644
index 00000000000..075d46b835f
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/mpx/pr79631.c
@@ -0,0 +1,15 @@
+/* { dg-do compile { target { ! x32 } } } */
+/* { dg-options "-fcheck-pointer-bounds -mmpx -O2" } */
+
+typedef struct { int _mp_size; } mpz_t[1];
+int a, b;
+void fn1()
+{
+  mpz_t c[1][b];
+  for (;;) {
+      int d = 0 >= 0 ? 0 == 0 ? c[0][0]->_mp_size ? -1 : 0 : 0 : 0,
+	  e = 0 >= 0 ? 0 == 0 ? c[1][1]->_mp_size ? -1 : 0 : 0 : 0;
+      if (d != e)
+	a++;
+  }
+}
diff --git a/gcc/tree-chkp-opt.c b/gcc/tree-chkp-opt.c
index 3fa2380d4bf..e594b332d76 100644
--- a/gcc/tree-chkp-opt.c
+++ b/gcc/tree-chkp-opt.c
@@ -282,9 +282,11 @@ chkp_is_constant_addr (const address_t &addr, int *sign)
     return false;
   else if (addr.pol[0].var)
     return false;
+  else if (TREE_CODE (addr.pol[0].cst) != INTEGER_CST)
+    return false;
   else if (integer_zerop (addr.pol[0].cst))
     *sign = 0;
-  else if  (tree_int_cst_sign_bit (addr.pol[0].cst))
+  else if (tree_int_cst_sign_bit (addr.pol[0].cst))
     *sign = -1;
   else
     *sign = 1;
-- 
2.12.0


[-- Attachment #9: 0008-Backport-r237353-r245997-r246027.patch --]
[-- Type: text/x-patch, Size: 3081 bytes --]

From cd55c88655fcaeb6729614745aaf0e8b68278410 Mon Sep 17 00:00:00 2001
From: marxin <marxin@138bc75d-0d04-0410-961f-82ee72b054a4>
Date: Mon, 13 Jun 2016 07:17:16 +0000
Subject: [PATCH 08/15] Backport r237353,r245997,r246027

gcc/ChangeLog:

2016-06-13  Martin Liska  <mliska@suse.cz>

	PR target/65705
	PR target/69804
	PR sanitizer/71458

	* toplev.c (process_options): Enable MPX with LSAN and UBSAN.
	* tree-chkp.c (chkp_walk_pointer_assignments): Verify that
	FIELD != NULL.

gcc/testsuite/ChangeLog:

2016-06-13  Martin Liska  <mliska@suse.cz>

	PR sanitizer/71458
	* gcc.target/i386/pr71458.c: New test.
---
 gcc/testsuite/gcc.target/i386/pr71458.c |  7 +++++++
 gcc/toplev.c                            | 21 +++++++++++++++++++--
 gcc/tree-chkp.c                         |  2 +-
 3 files changed, 27 insertions(+), 3 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/i386/pr71458.c

diff --git a/gcc/testsuite/gcc.target/i386/pr71458.c b/gcc/testsuite/gcc.target/i386/pr71458.c
new file mode 100644
index 00000000000..d36b61cbe02
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr71458.c
@@ -0,0 +1,7 @@
+/* { dg-do compile { target { ! x32 } } } */
+/* { dg-options "-fcheck-pointer-bounds -mmpx -fsanitize=bounds" } */
+/* { dg-error "'-fcheck-pointer-bounds' is not supported with '-fsanitize=bounds'" "" { target *-*-* } 0 } */
+
+enum {} a[0];
+void fn1(int);
+void fn2() { fn1(a[-1]); }
diff --git a/gcc/toplev.c b/gcc/toplev.c
index cb6c51739ff..c565ea4797e 100644
--- a/gcc/toplev.c
+++ b/gcc/toplev.c
@@ -1367,16 +1367,33 @@ process_options (void)
     {
       if (targetm.chkp_bound_mode () == VOIDmode)
 	{
-	  error ("-fcheck-pointer-bounds is not supported for this target");
+	  error ("%<-fcheck-pointer-bounds%> is not supported for this "
+		 "target");
 	  flag_check_pointer_bounds = 0;
 	}
 
+      if (flag_sanitize & SANITIZE_BOUNDS)
+	{
+	  error ("%<-fcheck-pointer-bounds%> is not supported with "
+		 "%<-fsanitize=bounds%>");
+ 	  flag_check_pointer_bounds = 0;
+ 	}
+
       if (flag_sanitize & SANITIZE_ADDRESS)
 	{
-	  error ("-fcheck-pointer-bounds is not supported with "
+	  error ("%<-fcheck-pointer-bounds%> is not supported with "
 		 "Address Sanitizer");
 	  flag_check_pointer_bounds = 0;
 	}
+
+      if (flag_sanitize & SANITIZE_THREAD)
+	{
+	  error (UNKNOWN_LOCATION,
+		 "%<-fcheck-pointer-bounds%> is not supported with "
+		 "Thread Sanitizer");
+
+	  flag_check_pointer_bounds = 0;
+	}
     }
 
   /* One region RA really helps to decrease the code size.  */
diff --git a/gcc/tree-chkp.c b/gcc/tree-chkp.c
index 237399ecc96..049bafae4e2 100644
--- a/gcc/tree-chkp.c
+++ b/gcc/tree-chkp.c
@@ -3690,7 +3690,7 @@ chkp_walk_pointer_assignments (tree lhs, tree rhs, void *arg,
 
 	  FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (rhs), cnt, field, val)
 	    {
-	      if (chkp_type_has_pointer (TREE_TYPE (field)))
+	      if (field && chkp_type_has_pointer (TREE_TYPE (field)))
 		{
 		  tree lhs_field = chkp_build_component_ref (lhs, field);
 		  chkp_walk_pointer_assignments (lhs_field, val, arg, handler);
-- 
2.12.0


[-- Attachment #10: 0009-Backport-r246098.patch --]
[-- Type: text/x-patch, Size: 1966 bytes --]

From 7e456669fa321fc59ff249ab95bf2f5f6f7e8867 Mon Sep 17 00:00:00 2001
From: marxin <marxin@138bc75d-0d04-0410-961f-82ee72b054a4>
Date: Mon, 13 Mar 2017 15:30:17 +0000
Subject: [PATCH 09/15] Backport r246098

gcc/ChangeLog:

2017-03-13  Martin Liska  <mliska@suse.cz>

	PR middle-end/78339
	* ipa-pure-const.c (warn_function_noreturn): If the declarations
	is a CHKP clone, use original declaration.

gcc/testsuite/ChangeLog:

2017-03-13  Martin Liska  <mliska@suse.cz>

	PR middle-end/78339
	* gcc.target/i386/mpx/pr78339.c: New test.
---
 gcc/ipa-pure-const.c                        | 8 +++++++-
 gcc/testsuite/gcc.target/i386/mpx/pr78339.c | 5 +++++
 2 files changed, 12 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.target/i386/mpx/pr78339.c

diff --git a/gcc/ipa-pure-const.c b/gcc/ipa-pure-const.c
index 8bfc649e148..f86d6fbbc40 100644
--- a/gcc/ipa-pure-const.c
+++ b/gcc/ipa-pure-const.c
@@ -249,11 +249,17 @@ warn_function_const (tree decl, bool known_finite)
 static void
 warn_function_noreturn (tree decl)
 {
+  tree original_decl = decl;
+
+  cgraph_node *node = cgraph_node::get (decl);
+  if (node->instrumentation_clone)
+    decl = node->instrumented_version->decl;
+
   static hash_set<tree> *warned_about;
   if (!lang_hooks.missing_noreturn_ok_p (decl)
       && targetm.warn_func_return (decl))
     warned_about 
-      = suggest_attribute (OPT_Wsuggest_attribute_noreturn, decl,
+      = suggest_attribute (OPT_Wsuggest_attribute_noreturn, original_decl,
 			   true, warned_about, "noreturn");
 }
 
diff --git a/gcc/testsuite/gcc.target/i386/mpx/pr78339.c b/gcc/testsuite/gcc.target/i386/mpx/pr78339.c
new file mode 100644
index 00000000000..3dd04240e8c
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/mpx/pr78339.c
@@ -0,0 +1,5 @@
+/* { dg-do compile } */
+/* { dg-options "-fcheck-pointer-bounds -mmpx -Wsuggest-attribute=noreturn" } */
+
+extern _Noreturn void exit (int);
+int main (void) { exit (1); }
-- 
2.12.0


[-- Attachment #11: 0010-Backport-r246129.patch --]
[-- Type: text/x-patch, Size: 1626 bytes --]

From 80b1d8da103e0495e579e4ff15bef3b244b0673a Mon Sep 17 00:00:00 2001
From: marxin <marxin@138bc75d-0d04-0410-961f-82ee72b054a4>
Date: Tue, 14 Mar 2017 15:31:53 +0000
Subject: [PATCH 10/15] Backport r246129

gcc/ChangeLog:

2017-03-14  Martin Liska  <mliska@suse.cz>

	PR middle-end/79831
	* doc/invoke.texi (-Wchkp): Document the option.
---
 gcc/doc/invoke.texi | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 1ca4dcc3221..05a04210002 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -245,7 +245,7 @@ Objective-C and Objective-C++ Dialects}.
 -Wno-attributes -Wno-builtin-macro-redefined @gol
 -Wc90-c99-compat -Wc99-c11-compat @gol
 -Wc++-compat -Wc++11-compat -Wc++14-compat -Wcast-align  -Wcast-qual  @gol
--Wchar-subscripts -Wclobbered  -Wcomment -Wconditionally-supported  @gol
+-Wchar-subscripts -Wchkp -Wclobbered  -Wcomment -Wconditionally-supported  @gol
 -Wconversion -Wcoverage-mismatch -Wdate-time -Wdelete-incomplete -Wno-cpp  @gol
 -Wno-deprecated -Wno-deprecated-declarations -Wno-designated-init @gol
 -Wdisabled-optimization @gol
@@ -3538,6 +3538,11 @@ Warn whenever a comment-start sequence @samp{/*} appears in a @samp{/*}
 comment, or whenever a Backslash-Newline appears in a @samp{//} comment.
 This warning is enabled by @option{-Wall}.
 
+@item -Wchkp
+@opindex Wchkp
+Warn about an invalid memory access that is found by Pointer Bounds Checker
+(@option{-fcheck-pointer-bounds}).
+
 @item -Wno-coverage-mismatch
 @opindex Wno-coverage-mismatch
 Warn if feedback profiles do not match when using the
-- 
2.12.0


[-- Attachment #12: 0011-Backport-r246275.patch --]
[-- Type: text/x-patch, Size: 2306 bytes --]

From 4b7929721b814546ffeb4d4beaa453915843f46c Mon Sep 17 00:00:00 2001
From: marxin <marxin@138bc75d-0d04-0410-961f-82ee72b054a4>
Date: Mon, 20 Mar 2017 10:04:06 +0000
Subject: [PATCH 11/15] Backport r246275

gcc/ChangeLog:

2017-03-20  Martin Liska  <mliska@suse.cz>

	PR target/79769
	PR target/79770
	* tree-chkp.c (chkp_find_bounds_1): Handle REAL_CST,
	COMPLEX_CST and VECTOR_CST.

gcc/testsuite/ChangeLog:

2017-03-20  Martin Liska  <mliska@suse.cz>

	PR target/79769
	PR target/79770
	* g++.dg/pr79769.C: New test.
	* gcc.target/i386/mpx/pr79770.c: New test.
---
 gcc/testsuite/g++.dg/pr79769.C              |  4 ++++
 gcc/testsuite/gcc.target/i386/mpx/pr79770.c | 19 +++++++++++++++++++
 gcc/tree-chkp.c                             |  2 ++
 3 files changed, 25 insertions(+)
 create mode 100644 gcc/testsuite/g++.dg/pr79769.C
 create mode 100644 gcc/testsuite/gcc.target/i386/mpx/pr79770.c

diff --git a/gcc/testsuite/g++.dg/pr79769.C b/gcc/testsuite/g++.dg/pr79769.C
new file mode 100644
index 00000000000..c3186877f60
--- /dev/null
+++ b/gcc/testsuite/g++.dg/pr79769.C
@@ -0,0 +1,4 @@
+/* { dg-do compile { target { { i?86-*-* x86_64-*-* } && { ! x32 } } } } */
+/* { dg-options "-fcheck-pointer-bounds -mmpx -mabi=ms" } */
+
+void a (_Complex) { a (3); }
diff --git a/gcc/testsuite/gcc.target/i386/mpx/pr79770.c b/gcc/testsuite/gcc.target/i386/mpx/pr79770.c
new file mode 100644
index 00000000000..0890fcc7bf1
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/mpx/pr79770.c
@@ -0,0 +1,19 @@
+/* { dg-do compile { target lp64 } } */
+/* { dg-options "-fcheck-pointer-bounds -mmpx -mabi=ms -Wno-psabi" } */
+
+typedef unsigned U __attribute__ ((vector_size (64)));
+typedef unsigned __int128 V __attribute__ ((vector_size (64)));
+
+static inline V
+bar (U u, U x, V v)
+{
+  v = (V)(U) { 0, ~0 };
+  v[x[0]] <<= u[-63];
+  return v;
+}
+
+V
+foo (U u)
+{
+  return bar (u, (U) {}, (V) {});
+}
diff --git a/gcc/tree-chkp.c b/gcc/tree-chkp.c
index 049bafae4e2..39a9f62df53 100644
--- a/gcc/tree-chkp.c
+++ b/gcc/tree-chkp.c
@@ -3618,6 +3618,8 @@ chkp_find_bounds_1 (tree ptr, tree ptr_src, gimple_stmt_iterator *iter)
       break;
 
     case INTEGER_CST:
+    case COMPLEX_CST:
+    case VECTOR_CST:
       if (integer_zerop (ptr_src))
 	bounds = chkp_get_none_bounds ();
       else
-- 
2.12.0


[-- Attachment #13: 0012-Backport-r246276.patch --]
[-- Type: text/x-patch, Size: 2885 bytes --]

From e3c4be217d5a06fdbfb6f86ca8a98a42086dfb81 Mon Sep 17 00:00:00 2001
From: marxin <marxin@138bc75d-0d04-0410-961f-82ee72b054a4>
Date: Mon, 20 Mar 2017 10:06:00 +0000
Subject: [PATCH 12/15] Backport r246276

gcc/ChangeLog:

2017-03-20  Martin Liska  <mliska@suse.cz>

	PR middle-end/79753
	* tree-chkp.c (chkp_build_returned_bound): Do not build
	returned bounds for a LHS that's not a BOUNDED_P type.

gcc/testsuite/ChangeLog:

2017-03-20  Martin Liska  <mliska@suse.cz>

	PR middle-end/79753
	* gcc.target/i386/mpx/pr79753.c: New test.
---
 gcc/testsuite/gcc.target/i386/mpx/pr79753.c | 14 ++++++++++++++
 gcc/tree-chkp.c                             | 11 ++++++-----
 2 files changed, 20 insertions(+), 5 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/i386/mpx/pr79753.c

diff --git a/gcc/testsuite/gcc.target/i386/mpx/pr79753.c b/gcc/testsuite/gcc.target/i386/mpx/pr79753.c
new file mode 100644
index 00000000000..9b7bc52e1ed
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/mpx/pr79753.c
@@ -0,0 +1,14 @@
+/* { dg-do compile } */
+/* { dg-options "-fcheck-pointer-bounds -mmpx -O2" } */
+
+int
+foo (void)
+{
+  return 0;
+}
+
+void
+bar (int **p)
+{
+  *p = (int *) (__UINTPTR_TYPE__) foo ();
+}
diff --git a/gcc/tree-chkp.c b/gcc/tree-chkp.c
index 39a9f62df53..824827768f4 100644
--- a/gcc/tree-chkp.c
+++ b/gcc/tree-chkp.c
@@ -2236,6 +2236,7 @@ chkp_build_returned_bound (gcall *call)
   tree bounds;
   gimple stmt;
   tree fndecl = gimple_call_fndecl (call);
+  tree lhs = gimple_call_lhs (call);
   unsigned int retflags;
 
   /* To avoid fixing alloca expands in targets we handle
@@ -2246,9 +2247,8 @@ chkp_build_returned_bound (gcall *call)
 	  || DECL_FUNCTION_CODE (fndecl) == BUILT_IN_ALLOCA_WITH_ALIGN))
     {
       tree size = gimple_call_arg (call, 0);
-      tree lb = gimple_call_lhs (call);
       gimple_stmt_iterator iter = gsi_for_stmt (call);
-      bounds = chkp_make_bounds (lb, size, &iter, true);
+      bounds = chkp_make_bounds (lhs, size, &iter, true);
     }
   /* We know bounds returned by set_bounds builtin call.  */
   else if (fndecl
@@ -2301,9 +2301,10 @@ chkp_build_returned_bound (gcall *call)
 
       bounds = chkp_find_bounds (gimple_call_arg (call, argno), &iter);
     }
-  else if (chkp_call_returns_bounds_p (call))
+  else if (chkp_call_returns_bounds_p (call)
+	   && BOUNDED_P (lhs))
     {
-      gcc_assert (TREE_CODE (gimple_call_lhs (call)) == SSA_NAME);
+      gcc_assert (TREE_CODE (lhs) == SSA_NAME);
 
       /* In general case build checker builtin call to
 	 obtain returned bounds.  */
@@ -2330,7 +2331,7 @@ chkp_build_returned_bound (gcall *call)
       print_gimple_stmt (dump_file, call, 0, TDF_VOPS|TDF_MEMSYMS);
     }
 
-  bounds = chkp_maybe_copy_and_register_bounds (gimple_call_lhs (call), bounds);
+  bounds = chkp_maybe_copy_and_register_bounds (lhs, bounds);
 
   return bounds;
 }
-- 
2.12.0


[-- Attachment #14: 0013-Backport-r246316.patch --]
[-- Type: text/x-patch, Size: 994 bytes --]

From 534038d98522ecd9a8695faa8996fda05a6b059e Mon Sep 17 00:00:00 2001
From: marxin <marxin@138bc75d-0d04-0410-961f-82ee72b054a4>
Date: Tue, 21 Mar 2017 12:01:40 +0000
Subject: [PATCH 13/15] Backport r246316

gcc/testsuite/ChangeLog:

2017-03-21  Martin Liska  <mliska@suse.cz>

	* gcc.target/i386/pr65044.c: Add '.' in order to catch
	apostrophes.
---
 gcc/testsuite/gcc.target/i386/pr65044.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/testsuite/gcc.target/i386/pr65044.c b/gcc/testsuite/gcc.target/i386/pr65044.c
index 3b129862aa9..24b038e56a9 100644
--- a/gcc/testsuite/gcc.target/i386/pr65044.c
+++ b/gcc/testsuite/gcc.target/i386/pr65044.c
@@ -1,4 +1,4 @@
-/* { dg-error "-fcheck-pointer-bounds is not supported with Address Sanitizer" } */
+/* { dg-error ".-fcheck-pointer-bounds. is not supported with Address Sanitizer" } */
 /* { dg-do compile { target { ! x32 } } } */
 /* { dg-options "-fcheck-pointer-bounds -mmpx -fsanitize=address" } */
 
-- 
2.12.0


[-- Attachment #15: 0014-Backport-r246321.patch --]
[-- Type: text/x-patch, Size: 6832 bytes --]

From c210cd5e6777be3acca40d2352cc3be2c3167dad Mon Sep 17 00:00:00 2001
From: marxin <marxin@138bc75d-0d04-0410-961f-82ee72b054a4>
Date: Tue, 21 Mar 2017 14:41:11 +0000
Subject: [PATCH 14/15] Backport r246321

gcc/ChangeLog:

2017-03-21  Martin Liska  <mliska@suse.cz>

	PR gcov-profile/80081
	* Makefile.in: Add gcov-dump and fix installation of gcov-tool.
	* doc/gcc.texi: Include gcov-dump stuff.
	* doc/gcov-dump.texi: New file.
---
 gcc/Makefile.in        | 11 ++++--
 gcc/doc/gcc.texi       |  3 ++
 gcc/doc/gcov-dump.texi | 93 ++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 105 insertions(+), 2 deletions(-)
 create mode 100644 gcc/doc/gcov-dump.texi

diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index f00600dd30d..c9fec159ef0 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -2897,7 +2897,7 @@ TEXI_GCC_FILES = gcc.texi gcc-common.texi gcc-vers.texi frontends.texi	\
 	 gcov.texi trouble.texi bugreport.texi service.texi		\
 	 contribute.texi compat.texi funding.texi gnu.texi gpl_v3.texi	\
 	 fdl.texi contrib.texi cppenv.texi cppopts.texi avr-mmcu.texi	\
-	 implement-c.texi implement-cxx.texi gcov-tool.texi
+	 implement-c.texi implement-cxx.texi gcov-tool.texi gcov-dump.texi
 
 # we explicitly use $(srcdir)/doc/tm.texi here to avoid confusion with
 # the generated tm.texi; the latter might have a more recent timestamp,
@@ -3020,7 +3020,7 @@ $(build_htmldir)/gccinstall/index.html: $(TEXI_GCCINSTALL_FILES)
 	$(SHELL) $(srcdir)/doc/install.texi2html
 
 MANFILES = doc/gcov.1 doc/cpp.1 doc/gcc.1 doc/gfdl.7 doc/gpl.7 \
-           doc/fsf-funding.7 doc/gcov-tool.1
+           doc/fsf-funding.7 doc/gcov-tool.1 doc/gcov-dump.1
 
 generated-manpages: man
 
@@ -3414,6 +3414,8 @@ install-man: lang.install-man \
 	$(DESTDIR)$(man1dir)/$(GCC_INSTALL_NAME)$(man1ext) \
 	$(DESTDIR)$(man1dir)/$(CPP_INSTALL_NAME)$(man1ext) \
 	$(DESTDIR)$(man1dir)/$(GCOV_INSTALL_NAME)$(man1ext) \
+	$(DESTDIR)$(man1dir)/$(GCOV_TOOL_INSTALL_NAME)$(man1ext) \
+	$(DESTDIR)$(man1dir)/$(GCOV_DUMP_INSTALL_NAME)$(man1ext) \
 	$(DESTDIR)$(man7dir)/fsf-funding$(man7ext) \
 	$(DESTDIR)$(man7dir)/gfdl$(man7ext) \
 	$(DESTDIR)$(man7dir)/gpl$(man7ext)
@@ -3443,6 +3445,11 @@ $(DESTDIR)$(man1dir)/$(GCOV_TOOL_INSTALL_NAME)$(man1ext): doc/gcov-tool.1 instal
 	-$(INSTALL_DATA) $< $@
 	-chmod a-x $@
 
+$(DESTDIR)$(man1dir)/$(GCOV_DUMP_INSTALL_NAME)$(man1ext): doc/gcov-dump.1 installdirs
+	-rm -f $@
+	-$(INSTALL_DATA) $< $@
+	-chmod a-x $@
+
 # Install all the header files built in the include subdirectory.
 install-headers: $(INSTALL_HEADERS_DIR)
 # Fix symlinks to absolute paths in the installed include directory to
diff --git a/gcc/doc/gcc.texi b/gcc/doc/gcc.texi
index ba6b60807d8..429a8138616 100644
--- a/gcc/doc/gcc.texi
+++ b/gcc/doc/gcc.texi
@@ -67,6 +67,7 @@ Texts being (a) (see below), and with the Back-Cover Texts being (b)
 * g++: (gcc).                  The GNU C++ compiler.
 * gcov: (gcc) Gcov.            @command{gcov}---a test coverage program.
 * gcov-tool: (gcc) Gcov-tool.  @command{gcov-tool}---an offline gcda profile processing program.
+* gcov-dump: (gcc) Gcov-dump.  @command{gcov-dump}---an offline gcda and gcno profile dump tool.
 @end direntry
 This file documents the use of the GNU compilers.
 @sp 1
@@ -140,6 +141,7 @@ Introduction, gccint, GNU Compiler Collection (GCC) Internals}.
 * Compatibility::   Binary Compatibility
 * Gcov::            @command{gcov}---a test coverage program.
 * Gcov-tool::       @command{gcov-tool}---an offline gcda profile processing program.
+* Gcov-dump::       @command{gcov-dump}---an offline gcda and gcno profile dump tool.
 * Trouble::         If you have trouble using GCC.
 * Bugs::            How, why and where to report bugs.
 * Service::         How To Get Help with GCC
@@ -167,6 +169,7 @@ Introduction, gccint, GNU Compiler Collection (GCC) Internals}.
 @include compat.texi
 @include gcov.texi
 @include gcov-tool.texi
+@include gcov-dump.texi
 @include trouble.texi
 @include bugreport.texi
 @include service.texi
diff --git a/gcc/doc/gcov-dump.texi b/gcc/doc/gcov-dump.texi
new file mode 100644
index 00000000000..d7931fd3a19
--- /dev/null
+++ b/gcc/doc/gcov-dump.texi
@@ -0,0 +1,93 @@
+@c Copyright (C) 2017 Free Software Foundation, Inc.
+@c This is part of the GCC manual.
+@c For copying conditions, see the file gcc.texi.
+
+@ignore
+@c man begin COPYRIGHT
+Copyright @copyright{} 2017 Free Software Foundation, Inc.
+
+Permission is granted to copy, distribute and/or modify this document
+under the terms of the GNU Free Documentation License, Version 1.3 or
+any later version published by the Free Software Foundation; with the
+Invariant Sections being ``GNU General Public License'' and ``Funding
+Free Software'', the Front-Cover texts being (a) (see below), and with
+the Back-Cover Texts being (b) (see below).  A copy of the license is
+included in the gfdl(7) man page.
+
+(a) The FSF's Front-Cover Text is:
+
+     A GNU Manual
+
+(b) The FSF's Back-Cover Text is:
+
+     You have freedom to copy and modify this GNU Manual, like GNU
+     software.  Copies published by the Free Software Foundation raise
+     funds for GNU development.
+@c man end
+@c Set file name and title for the man page.
+@setfilename gcov-dump
+@settitle offline gcda and gcno profile dump tool
+@end ignore
+
+@node Gcov-dump
+@chapter @command{gcov-dump}---an Offline Gcda and Gcno Profile Dump Tool
+
+@menu
+* Gcov-dump Intro::             Introduction to gcov-dump.
+* Invoking Gcov-dump::          How to use gcov-dump.
+@end menu
+
+@node Gcov-dump Intro
+@section Introduction to @command{gcov-dump}
+@c man begin DESCRIPTION
+
+@command{gcov-dump} is a tool you can use in conjunction with GCC to
+dump content of gcda and gcno profile files offline.
+
+@c man end
+
+@node Invoking Gcov-dump
+@section Invoking @command{gcov-dump}
+
+@smallexample
+Usage: gcov-dump @r{[}@var{OPTION}@r{]} ... @var{gcovfiles}
+@end smallexample
+
+@command{gcov-dump} accepts the following options:
+
+@ignore
+@c man begin SYNOPSIS
+gcov-dump [@option{-v}|@option{--version}]
+     [@option{-h}|@option{--help}]
+     [@option{-l}|@option{--long}]
+     [@option{-p}|@option{--positions}]
+     [@option{-w}|@option{--working-sets}] @var{gcovfiles}
+@c man end
+@end ignore
+
+@c man begin OPTIONS
+@table @gcctabopt
+@item -h
+@itemx --help
+Display help about using @command{gcov-dump} (on the standard output), and
+exit without doing any further processing.
+
+@item -v
+@itemx --version
+Display the @command{gcov-dump} version number (on the standard output),
+and exit without doing any further processing.
+
+@item -l
+@itemx --long
+Dump content of records.
+
+@item -p
+@itemx --positions
+Dump positions of records.
+
+@item -w
+@itemx --working-sets
+Dump working set computed from summary.
+@end table
+
+@c man end
-- 
2.12.0


[-- Attachment #16: 0015-Backport-r246345.patch --]
[-- Type: text/x-patch, Size: 1449 bytes --]

From a836b9520781f265eef7b54ded40f8fcaa7d77c5 Mon Sep 17 00:00:00 2001
From: marxin <marxin@138bc75d-0d04-0410-961f-82ee72b054a4>
Date: Wed, 22 Mar 2017 09:21:56 +0000
Subject: [PATCH 15/15] Backport r246345

gcc/ChangeLog:

2017-03-22  Martin Liska  <mliska@suse.cz>

	PR target/79906
	* config/rs6000/rs6000.c (rs6000_inner_target_options): Show
	error message instead of an ICE.

gcc/testsuite/ChangeLog:

2017-03-22  Martin Liska  <mliska@suse.cz>

	PR target/79906
	* g++.dg/ext/mv8.C: Add power* targets.
---
 gcc/config/rs6000/rs6000.c     | 5 ++++-
 gcc/testsuite/g++.dg/ext/mv8.C | 2 +-
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c
index 63b65dac4cc..cd3a73d6670 100644
--- a/gcc/config/rs6000/rs6000.c
+++ b/gcc/config/rs6000/rs6000.c
@@ -32628,7 +32628,10 @@ rs6000_inner_target_options (tree args, bool attr_p)
     }
 
   else
-    gcc_unreachable ();
+    {
+      error ("attribute %<target%> argument not a string");
+      return false;
+    }
 
   return ret;
 }
diff --git a/gcc/testsuite/g++.dg/ext/mv8.C b/gcc/testsuite/g++.dg/ext/mv8.C
index 2e98dd7ad85..bbf90b5a328 100644
--- a/gcc/testsuite/g++.dg/ext/mv8.C
+++ b/gcc/testsuite/g++.dg/ext/mv8.C
@@ -1,4 +1,4 @@
-// { dg-do compile { target i?86-*-* x86_64-*-* } }
+// { dg-do compile { target i?86-*-* x86_64-*-* powerpc*-*-* } }
 // { dg-options "" }
 
 __attribute__((target (11,12)))
-- 
2.12.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-05-29  9:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-29 10:04 Backport to GCC5 Martin Liška
  -- strict thread matches above, loose matches on Subject: below --
2017-03-22 10:15 Backport to GCC6 Martin Liška
2017-03-22 12:22 ` Backport to GCC5 Martin Liška

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).