[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: pure64 & -ftrapv



On Mon, 17 Jan 2005 19: 26:51 +0100, Kurt Roeckx wrote:

Hi Kurt Roeckx,
On Mon, 17 Jan 2005 19:26:51 +0100, Kurt Roeckx wrote:
> On Mon, Jan 17, 2005 at 07:37:37PM +1300, Adam Warner wrote:
>> Hi all,
>> 
>> I'm enjoying Debian pure64. It's astonishing how many applications have
>> been correctly ported. Many thanks for all the fantastic work!
>> 
>> #include <stdio.h>
>> #include <stdint.h>
>> 
>> int32_t a=0x7FFFFFFF;
>> 
>> int main(void) {
>>   printf("a+1=%i\n", a+1);
>>   return 0;
>> }
>> 
>> The above code compiled with gcc-3.3, gcc-3.4 and gcc-4.0 (pulled in from
>> gcc-3.4 experimental) and the -ftrapv option prints a+1=-214748364 each
>> time. It should abort.
> 
> It returns:
> a+1=-2147483648
> 
> No matter what I tried.
> Or did you make an error in pasting the result and lost the 8?

I made an error pasting in the result.

> -2147483648 is the result you should expect, but I assume your
> problem is that it's not generating a trap?

That's correct.

>> Once this works I going to attempt catching signed integer overflow to
>> promote dynamically typed signed 32-bit integer arithmetic to signed
>> 64-bit.
> [...]
> 
> Do you still have a question here?

Is this non-abort now solved: Does a very recent binary of CVS gcc abort?

The answer though is not too important. The code gcc generates on i386
appears highly suboptimal (it's a large procedure call that doesn't appear
to use the most appropriate x86 instructions). Plus the abort is optimised
out at -O2 and above.

It appears inline assembly is the only fast way to detect signed integer
overflow in GNU C. Without -ftrapv I can at least rely upon signed
integers silently wrapping for other purposes in GNU C.

I found this to be a helpful discussion of the issues with ptrdiff_t:
<http://weblogs.asp.net/oldnewthing/archive/2004/08/12/213468.aspx>

Regards,
Adam



Reply to: