]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
expr.c (string_constant): Account for non-zero lower bound arrays.
authorAndrew MacLeod <amacleod@redhat.com>
Thu, 7 Dec 2006 14:39:37 +0000 (14:39 +0000)
committerAndrew Macleod <amacleod@gcc.gnu.org>
Thu, 7 Dec 2006 14:39:37 +0000 (14:39 +0000)
2006-12-07  Andrew Macleod  <amacleod@redhat.com>

* expr.c (string_constant): Account for non-zero lower bound arrays.

From-SVN: r119623

gcc/ChangeLog
gcc/expr.c

index 0926c1dc55055fed788b97ce14e7280d12ec78a5..3c98eb1ffe902d7e8b469c02ebcaaec626f5be9b 100644 (file)
@@ -1,3 +1,7 @@
+2006-12-07  Andrew Macleod  <amacleod@redhat.com>
+
+       * expr.c (string_constant): Account for non-zero lower bound arrays.
+
 2006-12-07  Richard Guenther  <rguenther@suse.de>
 
        * builtins.c (expand_builtin_pow): Adjust predicates for
index 05bb9b80f6c735e18988aa29100e53242b18b335..9c2d2a64771c9852db3168cb06afc4fc7997ebcd 100644 (file)
@@ -8923,7 +8923,7 @@ is_aligning_offset (tree offset, tree exp)
 tree
 string_constant (tree arg, tree *ptr_offset)
 {
-  tree array, offset;
+  tree array, offset, lower_bound;
   STRIP_NOPS (arg);
 
   if (TREE_CODE (arg) == ADDR_EXPR)
@@ -8945,6 +8945,20 @@ string_constant (tree arg, tree *ptr_offset)
          if (TREE_CODE (array) != STRING_CST
              && TREE_CODE (array) != VAR_DECL)
            return 0;
+
+         /* Check if the array has a non-zero lower bound.  */
+         lower_bound = array_ref_low_bound (TREE_OPERAND (arg, 0));
+         if (!integer_zerop (lower_bound))
+           {
+             /* If the offset and base aren't both constants, return 0.  */
+             if (TREE_CODE (lower_bound) != INTEGER_CST)
+               return 0;
+             if (TREE_CODE (offset) != INTEGER_CST)
+               return 0;
+             /* Adjust offset by the lower bound.  */
+             offset = size_diffop (fold_convert (sizetype, offset), 
+                                   fold_convert (sizetype, lower_bound));
+           }
        }
       else
        return 0;