* RFA: Fix gcc test 20060102-1.c for 16-bit targets
@ 2007-09-19 11:20 Nick Clifton
2007-10-01 1:08 ` Mark Mitchell
0 siblings, 1 reply; 2+ messages in thread
From: Nick Clifton @ 2007-09-19 11:20 UTC (permalink / raw)
To: gcc-patches
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;
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: RFA: Fix gcc test 20060102-1.c for 16-bit targets
2007-09-19 11:20 RFA: Fix gcc test 20060102-1.c for 16-bit targets Nick Clifton
@ 2007-10-01 1:08 ` Mark Mitchell
0 siblings, 0 replies; 2+ messages in thread
From: Mark Mitchell @ 2007-10-01 1:08 UTC (permalink / raw)
To: Nick Clifton; +Cc: gcc-patches
Nick Clifton wrote:
> 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;
OK with __CHAR_BIT__ in place of 8.
--
Mark Mitchell
CodeSourcery
mark@codesourcery.com
(650) 331-3385 x713
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2007-10-01 1:08 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-09-19 11:20 RFA: Fix gcc test 20060102-1.c for 16-bit targets Nick Clifton
2007-10-01 1:08 ` Mark Mitchell
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).