This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH][C frontend] Fix PR24851
- From: Richard Guenther <rguenther at suse dot de>
- To: gcc-patches at gcc dot gnu dot org
- Date: Mon, 14 Nov 2005 18:02:49 +0100 (CET)
- Subject: [PATCH][C frontend] Fix PR24851
This fixes (or more like works around) the signed/unsinged mess. We
currently miscompile (C only)
void abort(void);
int main()
{
int a[10], *p, *q;
q = &a[1];
p = &q[-1];
if (p >= &a[9])
abort ();
return 0;
}
which can be fixed by not relying on fold_stmt re-constructing the
ARRAY_REF form out of wrong information but instead have the C frontend
just emit the ARRAY_REF instead of decomposing it.
Tested on x86_64-unknown-linux-gnu.
Ok for mainline?
Thanks,
Richard.
[ADDPATCH C]
2005-11-14 Richard Guenther <rguenther@suse.de>
PR middle-end/24851
* c-typeck.c (build_unary_op): Don't make x + y out of &x[y].
* gcc.c-torture/execute/pr24851.c: New testcase.
Index: c-typeck.c
===================================================================
*** c-typeck.c (revision 106885)
--- c-typeck.c (working copy)
*************** build_unary_op (enum tree_code code, tre
*** 2880,2896 ****
}
/* For &x[y], return x+y */
! if (TREE_CODE (arg) == ARRAY_REF)
! {
! tree op0 = TREE_OPERAND (arg, 0);
! if (!c_mark_addressable (op0))
! return error_mark_node;
! return build_binary_op (PLUS_EXPR,
! (TREE_CODE (TREE_TYPE (op0)) == ARRAY_TYPE
! ? array_to_pointer_conversion (op0)
! : op0),
! TREE_OPERAND (arg, 1), 1);
! }
/* Anything not already handled and not a true memory reference
or a non-lvalue array is an error. */
--- 2880,2888 ----
}
/* For &x[y], return x+y */
! if (TREE_CODE (arg) == ARRAY_REF
! && !c_mark_addressable (TREE_OPERAND (arg, 0)))
! return error_mark_node;
/* Anything not already handled and not a true memory reference
or a non-lvalue array is an error. */