This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

don't assume pointer cast to unsigned long is a valid initializer


This testcase fails on platforms that have pointers and longs with
different widths.  The problem is that truncation or extension of
pointers is not an operation that the compiler always accepts as
constant and, in general, when their widths differ, it fails this
testcase.  This patch fixes the problem in the testsuite so that we
use an integer type that is known (by GCC) to be exactly as wide as a
pointer, so that no potentially non-constant operations are
unnecessary.  I thought of using intptr_t, but I thought it wasn't
worth it.  Ok to install?

Index: gcc/testsuite/ChangeLog
from  Alexandre Oliva  <aoliva at redhat dot com>
	* gcc.c-torture/compile/20010327-1.c: Use __SIZE_TYPE__ instead of
	unsigned long.

Index: gcc/testsuite/gcc.c-torture/compile/20010327-1.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/gcc.c-torture/compile/20010327-1.c,v
retrieving revision 1.3
diff -u -p -r1.3 20010327-1.c
--- gcc/testsuite/gcc.c-torture/compile/20010327-1.c 15 Nov 2001 02:32:39 -0000 1.3
+++ gcc/testsuite/gcc.c-torture/compile/20010327-1.c 28 Feb 2003 08:12:12 -0000
@@ -1,2 +1,6 @@
 extern void _text;
-static unsigned long x = (unsigned long) &_text - 0x10000000L - 1;
+/* We use __SIZE_TYPE__ here because it's as wide as a pointer, so we
+   know we won't have a non-constant because of extension or
+   truncation of the pointer to fit.  */
+static __SIZE_TYPE__ x
+  = (__SIZE_TYPE__) &_text - (__SIZE_TYPE__) 0x10000000L - 1;
-- 
Alexandre Oliva   Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
Red Hat GCC Developer                 aoliva at {redhat dot com, gcc.gnu.org}
CS PhD student at IC-Unicamp        oliva at {lsd dot ic dot unicamp dot br, gnu.org}
Free Software Evangelist                Professional serial bug killer

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]