Remove wrong assert about gcov_type (PR lto/79587).
authorMartin Liska <mliska@suse.cz>
Wed, 22 Feb 2017 09:45:42 +0000 (10:45 +0100)
committerMartin Liska <marxin@gcc.gnu.org>
Wed, 22 Feb 2017 09:45:42 +0000 (09:45 +0000)
2017-02-22  Martin Liska  <mliska@suse.cz>

PR lto/79587
* data-streamer-in.c (streamer_read_gcov_count): Remove assert.
* data-streamer-out.c (streamer_write_gcov_count_stream):
Likewise.
* value-prof.c (stream_out_histogram_value): Make assert more
precise based on type of counter.
2017-02-22  Martin Liska  <mliska@suse.cz>

PR lto/79587
* gcc.dg/tree-prof/pr79587.c: New test.

From-SVN: r245647

gcc/ChangeLog
gcc/data-streamer-in.c
gcc/data-streamer-out.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/tree-prof/pr79587.c [new file with mode: 0644]
gcc/value-prof.c

index c0f554fed11ee3161f9ee04e21d77cfa41ce1b73..1911946edcd3bcf945c31dfdc2a04246247ef56d 100644 (file)
@@ -1,3 +1,12 @@
+2017-02-22  Martin Liska  <mliska@suse.cz>
+
+       PR lto/79587
+       * data-streamer-in.c (streamer_read_gcov_count): Remove assert.
+       * data-streamer-out.c (streamer_write_gcov_count_stream):
+       Likewise.
+       * value-prof.c (stream_out_histogram_value): Make assert more
+       precise based on type of counter.
+
 2017-02-21 Jeff Law  <law@redhat.com>
 
        PR tree-optimization/79621
index b38d91353fcf72d057f02488e4665a4cab35048a..ad32ce1e99a31aed64fc93a5badc6b0133f1e573 100644 (file)
@@ -181,7 +181,6 @@ gcov_type
 streamer_read_gcov_count (struct lto_input_block *ib)
 {
   gcov_type ret = streamer_read_hwi (ib);
-  gcc_assert (ret >= 0);
   return ret;
 }
 
index 1ee8c9f53af83001a078c0fa7b657880f5e70368..1e8feb1e74a44171730d7dcb0169d1d7ddbf3ecc 100644 (file)
@@ -340,7 +340,6 @@ streamer_write_hwi_stream (struct lto_output_stream *obs, HOST_WIDE_INT work)
 void
 streamer_write_gcov_count_stream (struct lto_output_stream *obs, gcov_type work)
 {
-  gcc_assert (work >= 0);
   gcc_assert ((HOST_WIDE_INT) work == work);
   streamer_write_hwi_stream (obs, work);
 }
index b76d0a31f8617e694c46dc4acbae4c35a345bad6..19ddc6efac8de5a2004ca87dc3f0744bff6ff161 100644 (file)
@@ -1,3 +1,8 @@
+2017-02-22  Martin Liska  <mliska@suse.cz>
+
+       PR lto/79587
+       * gcc.dg/tree-prof/pr79587.c: New test.
+
 2017-02-21  Marek Polacek  <polacek@redhat.com>
 
        PR c++/79535
diff --git a/gcc/testsuite/gcc.dg/tree-prof/pr79587.c b/gcc/testsuite/gcc.dg/tree-prof/pr79587.c
new file mode 100644 (file)
index 0000000..517e081
--- /dev/null
@@ -0,0 +1,26 @@
+/* { dg-require-effective-target lto } */
+/* { dg-options "-O2 -flto" } */
+
+unsigned long global = -12345;
+
+unsigned long
+__attribute__((noinline))
+test(unsigned long v, unsigned long v2)
+{
+  unsigned long x = v % v2;
+
+  return x;
+}
+
+int main(int argc, char **argv)
+{
+  unsigned long r = 0;
+
+  for (int i = 0; i < 100; i++)
+    r += test(argc, global);
+
+  if (r != 100)
+    __builtin_abort ();
+
+  return 0;
+}
index 097e4094095b1bf9c328b2af976206b28f44180e..22dc2c9e257019d0d8b7dd0dc8b6d7382585f3c3 100644 (file)
@@ -365,7 +365,17 @@ stream_out_histogram_value (struct output_block *ob, histogram_value hist)
       break;
     }
   for (i = 0; i < hist->n_counters; i++)
-    streamer_write_gcov_count (ob, hist->hvalue.counters[i]);
+    {
+      /* When user uses an unsigned type with a big value, constant converted
+        to gcov_type (a signed type) can be negative.  */
+      gcov_type value = hist->hvalue.counters[i];
+      if (hist->type == HIST_TYPE_SINGLE_VALUE && i == 0)
+       ;
+      else
+       gcc_assert (value >= 0);
+
+      streamer_write_gcov_count (ob, value);
+    }
   if (hist->hvalue.next)
     stream_out_histogram_value (ob, hist->hvalue.next);
 }