public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Fix undefined behaviour in profile_count::differs_from_p
@ 2023-08-10 16:56 Jan Hubicka
  0 siblings, 0 replies; only message in thread
From: Jan Hubicka @ 2023-08-10 16:56 UTC (permalink / raw)
  To: gcc-patches

Hi,
This patch avoid overflow in profile_count::differs_from_p and also makes it to
return false from one of the values is undefined while other is defined.

Bootstrapped/regtested x86_64-linux, comitted.

gcc/ChangeLog:

	* profile-count.cc (profile_count::differs_from_p): Fix overflow and
	handling of undefined values.

diff --git a/gcc/profile-count.cc b/gcc/profile-count.cc
index e63c9432388..a14f379db8f 100644
--- a/gcc/profile-count.cc
+++ b/gcc/profile-count.cc
@@ -128,13 +128,14 @@ profile_count::differs_from_p (profile_count other) const
 {
   gcc_checking_assert (compatible_p (other));
   if (!initialized_p () || !other.initialized_p ())
-    return false;
+    return initialized_p () != other.initialized_p ();
   if ((uint64_t)m_val - (uint64_t)other.m_val < 100
       || (uint64_t)other.m_val - (uint64_t)m_val < 100)
     return false;
   if (!other.m_val)
     return true;
-  int64_t ratio = (int64_t)m_val * 100 / other.m_val;
+  uint64_t ratio;
+  safe_scale_64bit (m_val, 100, other.m_val, &ratio);
   return ratio < 99 || ratio > 101;
 }
 

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-08-10 16:56 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-10 16:56 Fix undefined behaviour in profile_count::differs_from_p Jan Hubicka

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).