]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fix UBSAN in postreload-gcse.c (PR rtl-optimization/87868).
authorMartin Liska <mliska@suse.cz>
Wed, 7 Nov 2018 09:33:22 +0000 (10:33 +0100)
committerMartin Liska <marxin@gcc.gnu.org>
Wed, 7 Nov 2018 09:33:22 +0000 (09:33 +0000)
2018-11-07  Martin Liska  <mliska@suse.cz>

PR rtl-optimization/87868
* postreload-gcse.c (eliminate_partially_redundant_load): Set
threshold to max_count if we would overflow.
* profile-count.h: Make max_count a public constant.

From-SVN: r265869

gcc/ChangeLog
gcc/postreload-gcse.c
gcc/profile-count.h

index 2588ce226dcc72d7fe06f7c72806fdb8f10c02b8..cb50bad54ad21a902adfe273fd870862c46e92f1 100644 (file)
@@ -1,3 +1,10 @@
+2018-11-07  Martin Liska  <mliska@suse.cz>
+
+       PR rtl-optimization/87868
+       * postreload-gcse.c (eliminate_partially_redundant_load): Set
+       threshold to max_count if we would overflow.
+       * profile-count.h: Make max_count a public constant.
+
 2018-11-07  Martin Liska  <mliska@suse.cz>
 
        * mem-stats.h: Fix GNU coding style.
index b56993183d02294b9a2ea108fafa633ca1b57bd1..399970c368ae5ee048f8be31b6e8384880e7ef53 100644 (file)
@@ -1170,8 +1170,18 @@ eliminate_partially_redundant_load (basic_block bb, rtx_insn *insn,
   if (ok_count.to_gcov_type ()
       < GCSE_AFTER_RELOAD_PARTIAL_FRACTION * not_ok_count.to_gcov_type ())
     goto cleanup;
-  if (ok_count.to_gcov_type ()
-      < GCSE_AFTER_RELOAD_CRITICAL_FRACTION * critical_count.to_gcov_type ())
+
+  gcov_type threshold;
+#if (GCC_VERSION >= 5000)
+  if (__builtin_mul_overflow (GCSE_AFTER_RELOAD_CRITICAL_FRACTION,
+                             critical_count.to_gcov_type (), &threshold))
+    threshold = profile_count::max_count;
+#else
+  threshold
+    = GCSE_AFTER_RELOAD_CRITICAL_FRACTION * critical_count.to_gcov_type ();
+#endif
+
+  if (ok_count.to_gcov_type () < threshold)
     goto cleanup;
 
   /* Generate moves to the loaded register from where
index f4d0c340a0a999e26ac9f8e1f5b3ad940d5fcbe9..5d3bcc75f6d8374a28b9ca36410a7a890d8b30ff 100644 (file)
@@ -641,8 +641,8 @@ public:
      type to hold various extra stages.  */
 
   static const int n_bits = 61;
-private:
   static const uint64_t max_count = ((uint64_t) 1 << n_bits) - 2;
+private:
   static const uint64_t uninitialized_count = ((uint64_t) 1 << n_bits) - 1;
 
   uint64_t m_val : n_bits;