A question on POINTERS_EXTEND_UNSIGNED
H. J. Lu
hjl@lucon.org
Sun Aug 17 19:04:00 GMT 2003
Gcc uses some clever number theory for array indexing:
http://gcc.gnu.org/ml/gcc/2003-07/msg01382.html
For the code enclosed here, gcc depends on overflow to get
it right. However, when POINTERS_EXTEND_UNSIGNED is defined,
there are
#ifdef POINTERS_EXTEND_UNSIGNED
/* Given X, a memory address in ptr_mode, convert it to an address
in Pmode, or vice versa (TO_MODE says which way). We take advantage of
the fact that pointers are not allowed to overflow by commuting arithmetic
operations over conversions so that address arithmetic insns can be
used. */
rtx
convert_memory_address (to_mode, x)
enum machine_mode to_mode;
rtx x;
{
...
return convert_modes (to_mode, from_mode,
x, POINTERS_EXTEND_UNSIGNED);
}
#endif
in explow.c. For targets with
#define POINTERS_EXTEND_UNSIGNED 1
if to_mode is wider than from_mode, the index will be zero-extended,
which may lead to the wrong index computed due to overflow. How should
such a target deal with it?
H.J.
----
#include <stdio.h>
typedef struct
{
int i;
} foo;
static void
bar (foo *x, foo **y)
{
while (x->i != 0)
{
y [x->i - 0x70000000 + 34] = x++;
}
}
static foo *f [35];
int
main ()
{
foo i[2];
i [0].i = 0x70000000;
i [1].i = 0;
bar (i, f);
printf ("%p\n", f[34]);
printf ("%p\n", &i[0]);
return 0;
}
More information about the Gcc
mailing list