summaryrefslogtreecommitdiff
path: root/gcc/expr.c
diff options
context:
space:
mode:
authoramacleod <amacleod@138bc75d-0d04-0410-961f-82ee72b054a4>2006-12-07 14:39:37 +0000
committeramacleod <amacleod@138bc75d-0d04-0410-961f-82ee72b054a4>2006-12-07 14:39:37 +0000
commitde556b3259a3e20a3bba1b8b3d73336e39754e68 (patch)
treee1a24f3812cec9e295f4d039e3567910ce12e686 /gcc/expr.c
parent5a84ba55a56a2df5d389a73adf84d8fa7282cd97 (diff)
downloadgcc-de556b3259a3e20a3bba1b8b3d73336e39754e68.tar.gz
2006-12-07 Andrew Macleod <amacleod@redhat.com>
* expr.c (string_constant): Account for non-zero lower bound arrays. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@119623 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/expr.c')
-rw-r--r--gcc/expr.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/gcc/expr.c b/gcc/expr.c
index 05bb9b80f6c..9c2d2a64771 100644
--- a/gcc/expr.c
+++ b/gcc/expr.c
@@ -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;