This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/11968] New: Array reference is incorrectly computed for POINTERS_EXTEND_UNSIGNED
- From: "hjl at lucon dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 18 Aug 2003 16:07:21 -0000
- Subject: [Bug c/11968] New: Array reference is incorrectly computed for POINTERS_EXTEND_UNSIGNED
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11968
Summary: Array reference is incorrectly computed for
POINTERS_EXTEND_UNSIGNED
Product: gcc
Version: 3.4
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: hjl at lucon dot org
CC: gcc-bugs at gcc dot gnu dot org
When POINTERS_EXTEND_UNSIGNED is defined, array reference
may be incorrectly computed. In expr.c, there are
/* If we knew for certain that this is arithmetic for an array
reference, and we knew the bounds of the array, then we could
apply the distributive law across (PLUS X C) for constant C.
Without such knowledge, we risk overflowing the computation
when both X and C are large, but X+C isn't. */
/* ??? Could perhaps special-case EXP being unsigned and C being
positive. In that case we are certain that X+C is no smaller
than X and so the transformed expression will overflow iff the
original would have. */
if (GET_CODE (op0) != REG)
op0 = force_operand (op0, NULL_RTX);
if (GET_CODE (op0) != REG)
op0 = copy_to_mode_reg (mode, op0);
return gen_rtx_MULT (mode, op0,
gen_int_mode (tree_low_cst (exp1, 0),
TYPE_MODE (TREE_TYPE (exp1))));
However, the assumption is incorrect when POINTERS_EXTEND_UNSIGNED
is defined. In this case, we can't apply the distributive law ASIS
here. For
extern int array [];
...
array [x - 0x70000000]
If we transform it to
base - 0x70000000 * 4 + x * 4
base - 0x70000000 * 4 won't overflow.