From e765bccd227fce4e07f45682e301a701629901a0 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Tue, 2 Jan 2007 21:41:07 +0000 Subject: [PATCH] Make it work with gcc-4.3 snapshots. --- ChangeLog | 6 +++++ autoconf/intparam.c | 56 +++++++++++++++++++++++++++++---------------- 2 files changed, 42 insertions(+), 20 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1583bac..d233ac6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2006-12-24 Bruno Haible + + Make autoconfiguration work with gcc-4.3 snapshots. + * autoconf/intparam.c (main1): Rename get_integer_bitsize to + get_unsigned_integer_bitsize. New macro get_signed_integer_bitsize. + 2006-12-19 Bruno Haible * autoconf/intparam.c (main): Use 'return', not exit(). diff --git a/autoconf/intparam.c b/autoconf/intparam.c index 062eb7d..8879c4d 100644 --- a/autoconf/intparam.c +++ b/autoconf/intparam.c @@ -108,16 +108,32 @@ static boolean longlong_ulonglong_same; #endif void main1(void) { -#define get_integer_bitsize(type,where) \ - { type x = 1; \ - int bits = 0; \ - loop \ - { if (x==0) break; \ - x = x+x; \ - bits++; \ - if (bits==1000) { bits = -1; break; } \ - } \ - where = bits; \ +#define get_unsigned_integer_bitsize(type,where) \ + { type x = 1; \ + int bits = 0; \ + loop { \ + if (x==0) break; \ + x = x+x; \ + bits++; \ + if (bits==1000) { bits = -1; break; } \ + } \ + where = bits; \ + } +#define get_signed_integer_bitsize(type,unsigned_type,where) \ + { /* Signed integer overflow is "undefined behaviour" in C99, and gcc-4.3 \ + (without -fwrapv option) actually does weird things when signed integer \ + overflow occurs. Therefore perform the addition on the unsigned type. \ + Drawback: This will not detect cases where the signed type has more bits\ + than the unsigned type but the same size according to sizeof. Blech. */ \ + type x = 1; \ + int bits = 0; \ + loop { \ + if (x==0) break; \ + x = (unsigned_type)x + (unsigned_type)x;\ + bits++; \ + if (bits==1000) { bits = -1; break; } \ + } \ + where = bits; \ } #define print_integer_bitsize(type,typestr,where) \ { if (where >= 0) \ @@ -131,28 +147,28 @@ void main1(void) { if (!(where == char_bitsize * sizeof(type))) \ { printf("#error \"Formula BITSIZE(T) = SIZEOF(T) * BITSPERBYTE does not hold for t%spe %s!!\"\n","y",typestr); } \ } - get_integer_bitsize(schar,char_bitsize); - get_integer_bitsize(short,short_bitsize); - get_integer_bitsize(int,int_bitsize); - get_integer_bitsize(long,long_bitsize); + get_signed_integer_bitsize(schar,uchar,char_bitsize); + get_signed_integer_bitsize(short,ushort,short_bitsize); + get_signed_integer_bitsize(int,uint,int_bitsize); + get_signed_integer_bitsize(long,ulong,long_bitsize); print_integer_bitsize(schar,"char",char_bitsize); print_integer_bitsize(short,"short",short_bitsize); print_integer_bitsize(int,"int",int_bitsize); print_integer_bitsize(long,"long",long_bitsize); #ifdef HAVE_LONGLONG - get_integer_bitsize(longlong,longlong_bitsize); + get_signed_integer_bitsize(longlong,ulonglong,longlong_bitsize); print_integer_bitsize(longlong,"long long",longlong_bitsize); #endif - get_integer_bitsize(uchar,uchar_bitsize); - get_integer_bitsize(ushort,ushort_bitsize); - get_integer_bitsize(uint,uint_bitsize); - get_integer_bitsize(ulong,ulong_bitsize); + get_unsigned_integer_bitsize(uchar,uchar_bitsize); + get_unsigned_integer_bitsize(ushort,ushort_bitsize); + get_unsigned_integer_bitsize(uint,uint_bitsize); + get_unsigned_integer_bitsize(ulong,ulong_bitsize); print_integer_bitsize(uchar,"unsigned char",uchar_bitsize); print_integer_bitsize(ushort,"unsigned short",ushort_bitsize); print_integer_bitsize(uint,"unsigned int",uint_bitsize); print_integer_bitsize(ulong,"unsigned long",ulong_bitsize); #ifdef HAVE_LONGLONG - get_integer_bitsize(ulonglong,ulonglong_bitsize); + get_unsigned_integer_bitsize(ulonglong,ulonglong_bitsize); print_integer_bitsize(ulonglong,"unsigned long long",ulonglong_bitsize); #endif }