]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Handle integer constants up front.
authorAndrew MacLeod <amacleod@redhat.com>
Mon, 15 Dec 2025 21:26:19 +0000 (16:26 -0500)
committerAndrew MacLeod <amacleod@redhat.com>
Wed, 6 May 2026 13:34:17 +0000 (09:34 -0400)
If passed an integer constant, return that constant.

* gimple-fold.cc (get_maxval_strlen): Return the same value if
passed a constant.

gcc/gimple-fold.cc

index 4ec6cc65e3a701281d0939ec9244c05d34857220..6523904425554a243803da94550044d24364c8f1 100644 (file)
@@ -2012,6 +2012,11 @@ get_maxval_strlen (tree arg, strlen_range_kind rkind, tree *nonstr = NULL)
   /* A non-null NONSTR is meaningless when determining the maximum
      value of an integer ARG.  */
   gcc_assert (rkind != SRK_INT_VALUE || nonstr == NULL);
+
+  // If arg is already a constant, simply return it.
+  if (TREE_CODE (arg) == INTEGER_CST && rkind == SRK_INT_VALUE)
+    return arg;
+
   /* ARG must have an integral type when RKIND says so.  */
   gcc_assert (rkind != SRK_INT_VALUE || INTEGRAL_TYPE_P (TREE_TYPE (arg)));