https://gcc.gnu.org/g:796fa83a5c7adb0a81616329b542ff34ea79872b

commit 796fa83a5c7adb0a81616329b542ff34ea79872b
Author: Mikael Morin <mik...@gcc.gnu.org>
Date:   Wed May 14 10:40:17 2025 +0200

    Correction régression unsigned_23

Diff:
---
 gcc/tree.cc | 22 ++++++++++++++++------
 1 file changed, 16 insertions(+), 6 deletions(-)

diff --git a/gcc/tree.cc b/gcc/tree.cc
index 86e6515f9cee..1751778647cd 100644
--- a/gcc/tree.cc
+++ b/gcc/tree.cc
@@ -13060,12 +13060,22 @@ array_ref_up_bound (tree exp)
   if (domain_type && TYPE_MAX_VALUE (domain_type))
     {
       tree val = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TYPE_MAX_VALUE (domain_type), 
exp);
-      if (TREE_OPERAND (exp, 2))
-        return fold_build2_loc (EXPR_LOCATION (exp), PLUS_EXPR,
-                               TREE_TYPE (val), val,
-                               fold_convert_loc (EXPR_LOCATION (exp),
-                                                 TREE_TYPE (val),
-                                                 TREE_OPERAND (exp, 2)));
+      tree low_bnd = TREE_OPERAND (exp, 2);
+      if (low_bnd)
+       {
+         tree dom_min = TYPE_MIN_VALUE (domain_type);
+         tree off = fold_build2_loc (EXPR_LOCATION (exp), MINUS_EXPR,
+                                     TREE_TYPE (val),
+                                     fold_convert_loc (EXPR_LOCATION (low_bnd),
+                                                       TREE_TYPE (val),
+                                                       low_bnd),
+                                     fold_convert_loc (EXPR_LOCATION (dom_min),
+                                                       TREE_TYPE (val),
+                                                       dom_min));
+
+         return fold_build2_loc (EXPR_LOCATION (exp), PLUS_EXPR,
+                                 TREE_TYPE (val), val, off);
+       }
       else
        return val;
     }

Reply via email to