RFA: Fix gcc test 20060102-1.c for 16-bit targets

Nick Clifton nickc@redhat.com
Wed Sep 19 11:20:00 GMT 2007

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

  May I apply this patch please ?


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;

More information about the Gcc-patches mailing list