]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ipa-cp: Make ipcp_val_replacement_ok_p fail better
authorMartin Jambor <mjambor@suse.cz>
Tue, 24 Feb 2026 10:43:32 +0000 (11:43 +0100)
committerMartin Jambor <jamborm@gcc.gnu.org>
Tue, 24 Feb 2026 10:43:44 +0000 (11:43 +0100)
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.

gcc/ChangeLog:

2026-02-23  Martin Jambor  <mjambor@suse.cz>

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

index 5b7cb3cdb4345945448961b5cfa3f8415398762e..b4e01a92344ed8ece40cd13dfc2f9f22498b6be6 100644 (file)
@@ -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));
 }