* [Bug c/13421] IA32 bigmem pointer subtraction and ftrapv option causes unjustified program abort
2003-12-17 16:33 [Bug c/13421] New: IA32 bigmem pointer subtraction and ftrapv option causes unjustified program abort vik dot heyndrickx at pandora dot be
@ 2003-12-17 16:58 ` pinskia at gcc dot gnu dot org
2003-12-17 16:59 ` falk at debian dot org
` (12 subsequent siblings)
13 siblings, 0 replies; 19+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2003-12-17 16:58 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2003-12-17 16:43 -------
Pointers are signed on i386. Use a cast to unsigned to get the effect you want.
--
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13421
^ permalink raw reply [flat|nested] 19+ messages in thread
* [Bug c/13421] IA32 bigmem pointer subtraction and ftrapv option causes unjustified program abort
2003-12-17 16:33 [Bug c/13421] New: IA32 bigmem pointer subtraction and ftrapv option causes unjustified program abort vik dot heyndrickx at pandora dot be
2003-12-17 16:58 ` [Bug c/13421] " pinskia at gcc dot gnu dot org
@ 2003-12-17 16:59 ` falk at debian dot org
2003-12-17 17:05 ` pinskia at gcc dot gnu dot org
` (11 subsequent siblings)
13 siblings, 0 replies; 19+ messages in thread
From: falk at debian dot org @ 2003-12-17 16:59 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From falk at debian dot org 2003-12-17 16:58 -------
I don't understand why you consider this invalid. The code looks OK to me,
assuming the pointers were really gained from malloc. Could you elaborate?
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13421
^ permalink raw reply [flat|nested] 19+ messages in thread
* [Bug c/13421] IA32 bigmem pointer subtraction and ftrapv option causes unjustified program abort
2003-12-17 16:33 [Bug c/13421] New: IA32 bigmem pointer subtraction and ftrapv option causes unjustified program abort vik dot heyndrickx at pandora dot be
2003-12-17 16:58 ` [Bug c/13421] " pinskia at gcc dot gnu dot org
2003-12-17 16:59 ` falk at debian dot org
@ 2003-12-17 17:05 ` pinskia at gcc dot gnu dot org
2003-12-17 17:06 ` vik dot heyndrickx at pandora dot be
` (10 subsequent siblings)
13 siblings, 0 replies; 19+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2003-12-17 17:05 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2003-12-17 17:01 -------
Pointers are signed so the subtraction is also signed which causes this problem.
If you want to use the difference without the abort from -ftrapv then do (unsgined)(a)-
(unsigned)(b).
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13421
^ permalink raw reply [flat|nested] 19+ messages in thread
* [Bug c/13421] IA32 bigmem pointer subtraction and ftrapv option causes unjustified program abort
2003-12-17 16:33 [Bug c/13421] New: IA32 bigmem pointer subtraction and ftrapv option causes unjustified program abort vik dot heyndrickx at pandora dot be
` (2 preceding siblings ...)
2003-12-17 17:05 ` pinskia at gcc dot gnu dot org
@ 2003-12-17 17:06 ` vik dot heyndrickx at pandora dot be
2003-12-17 17:28 ` pinskia at gcc dot gnu dot org
` (9 subsequent siblings)
13 siblings, 0 replies; 19+ messages in thread
From: vik dot heyndrickx at pandora dot be @ 2003-12-17 17:06 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From vik dot heyndrickx at pandora dot be 2003-12-17 17:03 -------
That is a (working) workaround, not a solution IMHO.
The workaround you propose means that basically any subtraction of any pair of
pointer need to be casted to unsigned because in theory any data structure may
end up near the middle of the address space. Otherwise anyone risks random
aborts.
Even more, if I would want to write a portable program, I cannot do it using
your proposed workaround because in general there is no such thing as an
integer data type that can hold a pointer.
--
What |Removed |Added
----------------------------------------------------------------------------
Status|RESOLVED |UNCONFIRMED
Resolution|INVALID |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13421
^ permalink raw reply [flat|nested] 19+ messages in thread
* [Bug c/13421] IA32 bigmem pointer subtraction and ftrapv option causes unjustified program abort
2003-12-17 16:33 [Bug c/13421] New: IA32 bigmem pointer subtraction and ftrapv option causes unjustified program abort vik dot heyndrickx at pandora dot be
` (3 preceding siblings ...)
2003-12-17 17:06 ` vik dot heyndrickx at pandora dot be
@ 2003-12-17 17:28 ` pinskia at gcc dot gnu dot org
2003-12-17 18:20 ` vik dot heyndrickx at pandora dot be
` (8 subsequent siblings)
13 siblings, 0 replies; 19+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2003-12-17 17:28 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2003-12-17 17:16 -------
But pointers are singed so you have to, sorry but that is the only way for this to work.
--
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13421
^ permalink raw reply [flat|nested] 19+ messages in thread
* [Bug c/13421] IA32 bigmem pointer subtraction and ftrapv option causes unjustified program abort
2003-12-17 16:33 [Bug c/13421] New: IA32 bigmem pointer subtraction and ftrapv option causes unjustified program abort vik dot heyndrickx at pandora dot be
` (4 preceding siblings ...)
2003-12-17 17:28 ` pinskia at gcc dot gnu dot org
@ 2003-12-17 18:20 ` vik dot heyndrickx at pandora dot be
2003-12-17 18:22 ` pinskia at gcc dot gnu dot org
` (7 subsequent siblings)
13 siblings, 0 replies; 19+ messages in thread
From: vik dot heyndrickx at pandora dot be @ 2003-12-17 18:20 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From vik dot heyndrickx at pandora dot be 2003-12-17 17:28 -------
Is there any need for having pointers to be signed?
Is there any need for -ftrapv checks to be done on pointers even when they are
signed?
Could the GCC documentation to be changed, so that it mentions that if -ftrapv
is used, a perfectly legal program may and will crash unexpectedly and randomly
on signed pointer platforms...
--
What |Removed |Added
----------------------------------------------------------------------------
Status|RESOLVED |UNCONFIRMED
Resolution|INVALID |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13421
^ permalink raw reply [flat|nested] 19+ messages in thread
* [Bug c/13421] IA32 bigmem pointer subtraction and ftrapv option causes unjustified program abort
2003-12-17 16:33 [Bug c/13421] New: IA32 bigmem pointer subtraction and ftrapv option causes unjustified program abort vik dot heyndrickx at pandora dot be
` (5 preceding siblings ...)
2003-12-17 18:20 ` vik dot heyndrickx at pandora dot be
@ 2003-12-17 18:22 ` pinskia at gcc dot gnu dot org
2003-12-17 18:23 ` falk dot hueffner at student dot uni-tuebingen dot de
` (6 subsequent siblings)
13 siblings, 0 replies; 19+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2003-12-17 18:22 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2003-12-17 17:53 -------
Pointers signness are determined by the ABI.
Here are the list of targets that are unsigned:
./alpha/vms.h:#define POINTERS_EXTEND_UNSIGNED 0
./ia64/hpux.h:#define POINTERS_EXTEND_UNSIGNED -1
./mips/mips.h:#define POINTERS_EXTEND_UNSIGNED 0
./s390/s390.h:#define POINTERS_EXTEND_UNSIGNED -1
./sparc/sparc.h:#define POINTERS_EXTEND_UNSIGNED 1
There are not many.
-ftrapv is done for all signed "addition, subtraction, multiplication operations".
So this is a request for documentation about -ftrapv and pointer arightatic.
--
What |Removed |Added
----------------------------------------------------------------------------
Severity|critical |minor
Status|UNCONFIRMED |NEW
Ever Confirmed| |1
Keywords| |documentation
Last reconfirmed|0000-00-00 00:00:00 |2003-12-17 17:53:14
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13421
^ permalink raw reply [flat|nested] 19+ messages in thread
* [Bug c/13421] IA32 bigmem pointer subtraction and ftrapv option causes unjustified program abort
2003-12-17 16:33 [Bug c/13421] New: IA32 bigmem pointer subtraction and ftrapv option causes unjustified program abort vik dot heyndrickx at pandora dot be
` (6 preceding siblings ...)
2003-12-17 18:22 ` pinskia at gcc dot gnu dot org
@ 2003-12-17 18:23 ` falk dot hueffner at student dot uni-tuebingen dot de
2003-12-17 18:38 ` zack at gcc dot gnu dot org
` (5 subsequent siblings)
13 siblings, 0 replies; 19+ messages in thread
From: falk dot hueffner at student dot uni-tuebingen dot de @ 2003-12-17 18:23 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From falk dot hueffner at student dot uni-tuebingen dot de 2003-12-17 18:05 -------
Subject: Re: IA32 bigmem pointer subtraction and ftrapv option causes unjustified program abort
"pinskia at gcc dot gnu dot org" <gcc-bugzilla@gcc.gnu.org> writes:
> ------- Additional Comments From pinskia at gcc dot gnu dot org 2003-12-17 17:53 -------
> Pointers signness are determined by the ABI.
> Here are the list of targets that are unsigned:
> ./alpha/vms.h:#define POINTERS_EXTEND_UNSIGNED 0
> ./ia64/hpux.h:#define POINTERS_EXTEND_UNSIGNED -1
> ./mips/mips.h:#define POINTERS_EXTEND_UNSIGNED 0
> ./s390/s390.h:#define POINTERS_EXTEND_UNSIGNED -1
> ./sparc/sparc.h:#define POINTERS_EXTEND_UNSIGNED 1
> There are not many.
> -ftrapv is done for all signed "addition, subtraction,
> multiplication operations". So this is a request for documentation
> about -ftrapv and pointer arightatic.
Pointer signedness is an implementation detail which should not matter
to conforming programs IMHO. Also I would suppose it is feasible to
generate unsigned difference/division for pointer difference on any
platform.
Roger, you fixed bug 1823 which is related. Do you have any opinion on
this?
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13421
^ permalink raw reply [flat|nested] 19+ messages in thread
* [Bug c/13421] IA32 bigmem pointer subtraction and ftrapv option causes unjustified program abort
2003-12-17 16:33 [Bug c/13421] New: IA32 bigmem pointer subtraction and ftrapv option causes unjustified program abort vik dot heyndrickx at pandora dot be
` (7 preceding siblings ...)
2003-12-17 18:23 ` falk dot hueffner at student dot uni-tuebingen dot de
@ 2003-12-17 18:38 ` zack at gcc dot gnu dot org
2003-12-18 11:46 ` bangerth at dealii dot org
` (4 subsequent siblings)
13 siblings, 0 replies; 19+ messages in thread
From: zack at gcc dot gnu dot org @ 2003-12-17 18:38 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From zack at gcc dot gnu dot org 2003-12-17 18:21 -------
1) Indeed, this subtraction operation should work fine whether or not pointers
are unsigned, and whether or not -ftrapv is in use. This is not a documentation
bug.
2) POINTERS_EXTEND_UNSIGNED does not mean what you think it means. From the manual:
`POINTERS_EXTEND_UNSIGNED'
A C expression whose value is greater than zero if pointers that
need to be extended from being `POINTER_SIZE' bits wide to `Pmode'
are to be zero-extended and zero if they are to be sign-extended.
If the value is less then zero then there must be an "ptr_extend"
instruction that extends a pointer from `POINTER_SIZE' to `Pmode'.
You need not define this macro if the `POINTER_SIZE' is equal to
the width of `Pmode'.
In particular, this *only* affects extension of pointers from POINTER_SIZE to
Pmode. It says *nothing* about whether address arithmetic should be treated as
signed. I don't think we even have a way of talking about that.
--
What |Removed |Added
----------------------------------------------------------------------------
Severity|minor |normal
Keywords|documentation |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13421
^ permalink raw reply [flat|nested] 19+ messages in thread
* [Bug c/13421] IA32 bigmem pointer subtraction and ftrapv option causes unjustified program abort
2003-12-17 16:33 [Bug c/13421] New: IA32 bigmem pointer subtraction and ftrapv option causes unjustified program abort vik dot heyndrickx at pandora dot be
` (8 preceding siblings ...)
2003-12-17 18:38 ` zack at gcc dot gnu dot org
@ 2003-12-18 11:46 ` bangerth at dealii dot org
2003-12-18 12:46 ` vik dot heyndrickx at pandora dot be
` (3 subsequent siblings)
13 siblings, 0 replies; 19+ messages in thread
From: bangerth at dealii dot org @ 2003-12-18 11:46 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From bangerth at dealii dot org 2003-12-18 10:39 -------
Just as a sidenote: the integer type that can hold pointers is, at
least in C++, ptrdiff_t. Casting to this type should get you where
you want.
W.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13421
^ permalink raw reply [flat|nested] 19+ messages in thread
* [Bug c/13421] IA32 bigmem pointer subtraction and ftrapv option causes unjustified program abort
2003-12-17 16:33 [Bug c/13421] New: IA32 bigmem pointer subtraction and ftrapv option causes unjustified program abort vik dot heyndrickx at pandora dot be
` (9 preceding siblings ...)
2003-12-18 11:46 ` bangerth at dealii dot org
@ 2003-12-18 12:46 ` vik dot heyndrickx at pandora dot be
2003-12-18 13:34 ` bangerth at dealii dot org
` (2 subsequent siblings)
13 siblings, 0 replies; 19+ messages in thread
From: vik dot heyndrickx at pandora dot be @ 2003-12-18 12:46 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From vik dot heyndrickx at pandora dot be 2003-12-18 12:21 -------
(In reply to comment #10)
> Just as a sidenote: the integer type that can hold pointers is, at
> least in C++, ptrdiff_t. Casting to this type should get you where
> you want.
No, it won't. ptrdiff_t exists also in C by the way. The problem is not the
result of the subtraction but the subtraction itself.
In essence the problem is the signedness of pointers. Later on, I realizes that
when p is a pointer, and q is set to e.g. p + 2, that q < p for some values of
p (e.g. (void*)0x7FFFFFFFu) on IA32. Signedness and an addressible flat memory
space larger than 2^31 are not compatible.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13421
^ permalink raw reply [flat|nested] 19+ messages in thread
* [Bug c/13421] IA32 bigmem pointer subtraction and ftrapv option causes unjustified program abort
2003-12-17 16:33 [Bug c/13421] New: IA32 bigmem pointer subtraction and ftrapv option causes unjustified program abort vik dot heyndrickx at pandora dot be
` (10 preceding siblings ...)
2003-12-18 12:46 ` vik dot heyndrickx at pandora dot be
@ 2003-12-18 13:34 ` bangerth at dealii dot org
2003-12-19 11:05 ` vik dot heyndrickx at pandora dot be
2004-04-06 5:13 ` [Bug middle-end/13421] " eggert at twinsun dot com
13 siblings, 0 replies; 19+ messages in thread
From: bangerth at dealii dot org @ 2003-12-18 13:34 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From bangerth at dealii dot org 2003-12-18 13:11 -------
Well, if prtdiff_t doesn't work, I would say that this is a bug in gcc.
That's also what Zack says in his first point.
W.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13421
^ permalink raw reply [flat|nested] 19+ messages in thread
* [Bug c/13421] IA32 bigmem pointer subtraction and ftrapv option causes unjustified program abort
2003-12-17 16:33 [Bug c/13421] New: IA32 bigmem pointer subtraction and ftrapv option causes unjustified program abort vik dot heyndrickx at pandora dot be
` (11 preceding siblings ...)
2003-12-18 13:34 ` bangerth at dealii dot org
@ 2003-12-19 11:05 ` vik dot heyndrickx at pandora dot be
2004-04-06 5:13 ` [Bug middle-end/13421] " eggert at twinsun dot com
13 siblings, 0 replies; 19+ messages in thread
From: vik dot heyndrickx at pandora dot be @ 2003-12-19 11:05 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From vik dot heyndrickx at pandora dot be 2003-12-19 10:23 -------
(In reply to comment #11)
> Later on, I realizes that when p is a pointer, and q is set to
> e.g. p + 2, that q < p for some values of p
> (e.g. (void*)0x7FFFFFFFu) on IA32. Signedness and an addressible
> flat memory space larger than 2^31 are not compatible.
To my big surprise I found out today that pointer on IA32 are treated as
unsigneds. At least when comparing pointers. The IA32 asm code for comparing
unsigneds and pointers is the same. It differs for signeds.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13421
^ permalink raw reply [flat|nested] 19+ messages in thread
* [Bug middle-end/13421] IA32 bigmem pointer subtraction and ftrapv option causes unjustified program abort
2003-12-17 16:33 [Bug c/13421] New: IA32 bigmem pointer subtraction and ftrapv option causes unjustified program abort vik dot heyndrickx at pandora dot be
` (12 preceding siblings ...)
2003-12-19 11:05 ` vik dot heyndrickx at pandora dot be
@ 2004-04-06 5:13 ` eggert at twinsun dot com
13 siblings, 0 replies; 19+ messages in thread
From: eggert at twinsun dot com @ 2004-04-06 5:13 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From eggert at twinsun dot com 2004-04-06 05:13 -------
A point of clarification: even if pointers are changed to be consistently
unsigned internally (which seems to be the right thing to do, if pointer
comparison is unsigned), GCC must still check for overflow when subtracting
pointers. For example, suppose we have the 2 GiB array "a" successfully
allocated by "char *a = malloc (1u<<31);". Then the expression "(a + (1u<<31)) -
a" is of type ptrdiff_t, which is a signed 32-bit integer that cannot represent
(1u<<31). So this expression must generate a trap with -ftrapv, regardless of
whether pointers are unsigned internally.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13421
^ permalink raw reply [flat|nested] 19+ messages in thread