]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Check if constant is a member before returning it.
authorAndrew MacLeod <amacleod@redhat.com>
Tue, 10 Jun 2025 16:11:18 +0000 (12:11 -0400)
committerAndrew MacLeod <amacleod@redhat.com>
Tue, 10 Jun 2025 16:31:30 +0000 (12:31 -0400)
set_range_from_bitmask checks the new bitmask, and if it is a constant,
simply returns the constant.  It never checks if that constant is
actually within the range.  If it is not, the result should be UNDEFINED.

* value-range.cc (irange::set_range_from_bitmask): When the bitmask
result is a singleton, check if it is contained in the range.

gcc/value-range.cc

index ed3760fa6ff64e51b80df2c3c75dc975ab034fe7..e2d75f59c2e0c9c5228114ef8be2e1a994ec376c 100644 (file)
@@ -2268,7 +2268,11 @@ irange::set_range_from_bitmask ()
   // If all the bits are known, this is a singleton.
   if (m_bitmask.mask () == 0)
     {
-      set (m_type, m_bitmask.value (), m_bitmask.value ());
+      // Make sure the singleton is within the range.
+      if (contains_p (m_bitmask.value ()))
+       set (m_type, m_bitmask.value (), m_bitmask.value ());
+      else
+       set_undefined ();
       return true;
     }