This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Why convert to pointer type before added to a pointer
- From: Jeffrey A Law <law at redhat dot com>
- To: Jie Zhang <zhangjie at magima dot com dot cn>
- Cc: gcc at gcc dot gnu dot org
- Date: Mon, 16 Aug 2004 23:54:10 -0600
- Subject: Re: Why convert to pointer type before added to a pointer
- Organization: Red Hat, Inc
- References: <4120866A.5080709@magima.com.cn>
- Reply-to: law at redhat dot com
On Mon, 2004-08-16 at 04:03, Jie Zhang wrote:
> This simple code
>
> void
> foo (int* a, int n)
> {
> a[n] = 1;
> }
>
> is transformed into
>
> foo (a, n)
> {
> unsigned int n.0;
> unsigned int T.1;
> int * T.2;
> int * T.3;
>
> n.0 = (unsigned int)n;
> T.1 = n.0 * 4;
> T.2 = (int *)T.1; <== Why this converting
> T.3 = T.2 + a;
> *T.3 = 1;
> }
>
> after the genericizing. Thanks.
It's an unfortunate aspect of the type system we have -- basically
both operands of a binary operator need to have compatible types.
I spent some time investigating ways to fix this in the context of
solving some long standing problems with the PA, IA-64 and mn10300
ports.
The first approach is to have a separate set of operators such as
PLUS_PTR_EXPR, MINUS_PTR_EXPR which do not require their operands
to be the same type. That's ugly simply because everywhere you
generate or test for PLUS_EXPR or MINUS_EXPR you have to to examine
the types to determine instead you should be using PLUS_PTR_EXPR
or MINUS_PTR_EXPR.
The other approach is to relax the type system. That's bad from the
standpoint of being able to perform internal consistency checking.
Right now we just convert the index to a pointer type and hope
everything works out in the end. That's not particularly good
either and has led to a little hack in how we compute REG_POINTER_FLAG
when converting from trees into RTL.
jeff