This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
RFA: Fix gcc test 20060102-1.c for 16-bit targets
- From: Nick Clifton <nickc at redhat dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Wed, 19 Sep 2007 11:45:35 +0100
- Subject: RFA: Fix gcc test 20060102-1.c for 16-bit targets
Hi Guys,
The gcc testsuite test gcc.c-torture/execute/20060102-1.c can fail
for targets which do not have integers of at least 32-bits. The
reason is this code:
int f(int x)
{
return (x >> 31) ? -1 : 1;
The ISO C99 specification says that shifting a variable by more than
the width of its type is undefined. One a 16-bit target therefore
the size of x will be 16 and "x >> 31" is undefined.
I have a proposed patch to fix this test (see below) although I am a
little bit concerned with it because it assumes that a byte is
8-bits wide. The patched test will still pass on targets with a
larger than 8-bit byte, but I am not sure if the test will still be
checking whatever bug it was that the test was originally created to
reproduce.
May I apply this patch please ?
Cheers
Nick
gcc/testsuite
2007-09-19 Nick Clifton <nickc@redhat.com>
* gcc.c-torture/execute/20060102-1.c: Fix test to work
for 16-bit targets.
Index: gcc/testsuite/gcc.c-torture/execute/20060102-1.c
===================================================================
--- gcc/testsuite/gcc.c-torture/execute/20060102-1.c (revision 128597)
+++ gcc/testsuite/gcc.c-torture/execute/20060102-1.c (working copy)
@@ -2,7 +2,7 @@ extern void abort ();
int f(int x)
{
- return (x >> 31) ? -1 : 1;
+ return (x >> (sizeof (x) * 8 - 1)) ? -1 : 1;
}
volatile int one = 1;