Non-standard test?

YuGr tetra2005@googlemail.com
Mon Jan 18 11:25:00 GMT 2010


Hi all,

I have recently run into a non-portable c-torture test  
(gcc.c-torture/execute/20030128-1.c) and would like to suggest an update for 
it.

The test performs division of unsigned char by (signed) short:

unsigned char x = 50;
volatile short y = -5;

int main ()
{
  x /= y;

and checks that signed division operation is performed:
if (x != (unsigned char) -10)
  abort ();

But according to C99 Standard (see Usual arithmetic conversions, 6.3.1.8):
1) "if the operand that has unsigned integer type has rank greater or equal to 
the rank of the type of the other operand, then the operand with signed 
integer type is converted to the type of the operand with unsigned integer 
type."
2) "Otherwise, if the type of the operand with signed integer type can 
represent all of the values of the type of the operand with unsigned integer 
type, then the operand with unsigned integer type is converted to the type of 
the operand with signed integer type."

so signed division is performed only if SHRT_MAX > UCHAR_MAX (otherwise 
division is unsigned).

I suggest to change the test to

if( SHRT_MAX > UCHAR_MAX && x != (unsigned char) -10)
  abort ();

(see the attached patch).

If I am correct, could someone commit the patch? I am not a gcc developer.

-- 
Best regards,
Yuri
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 20030128-1.c.patch
Type: text/x-diff
Size: 539 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/gcc/attachments/20100118/210836c7/attachment.bin>


More information about the Gcc mailing list