Hi,

This is a small improvement to a function which verifies that the
polymorphic context IPA-CP has decided to clone for is indeed among
the known contexts collected for the specialized node.  When no
context has been collected and the vector is empty, like in the case
of PR123629, the function will return false rather than ICE because of
an out of bounds vector access.  That in turn also results in an
ICE, but hopefully the error will be somewhat clearer.

Bootstrapped and tested on x86_64-linux, I will commit it shortly as
obvious.

Thanks,

Martin


gcc/ChangeLog:

2026-02-23  Martin Jambor  <[email protected]>

        PR ipa/123629
        * ipa-cp.cc (ipcp_val_replacement_ok_p): Also verify that the
        vector of known contexts has sufficient length.
---
 gcc/ipa-cp.cc | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/gcc/ipa-cp.cc b/gcc/ipa-cp.cc
index 5b7cb3cdb43..b4e01a92344 100644
--- a/gcc/ipa-cp.cc
+++ b/gcc/ipa-cp.cc
@@ -5922,7 +5922,8 @@ ipcp_val_replacement_ok_p (vec<tree> &,
 {
   if (offset != -1)
     return false;
-  return (!known_contexts[index].useless_p ()
+  return (known_contexts.length () > (unsigned) index
+         && !known_contexts[index].useless_p ()
          && known_contexts[index].equal_to (value));
 }
 
-- 
2.52.0

Reply via email to