emacs-pretest-bug
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: warnings compiling Emacs 22 on amd64


From: Francesco Potorti`
Subject: Re: warnings compiling Emacs 22 on amd64
Date: Mon, 11 Dec 2006 13:43:17 +0100

>> I get these warnings during compilation on x86_64-unknown-linux-gnu with
>> Debian testing with gcc (GCC) 4.1.2 20061028 (prerelease) (Debian 4.1.1-19)
>> [...]
>> gcc -c -D_BSD_SOURCE   -Demacs -DHAVE_CONFIG_H   -I. 
>> -I/home/pot/gnu/emacs-22.0.91/src -D_BSD_SOURCE  -g -O2 -Wno-pointer-sign  
>> editfns.c
>> editfns.c: In function 'Fuser_uid':
>> editfns.c:1317: warning: comparison is always false due to limited range of 
>> data type
>> editfns.c:1317: warning: comparison is always false due to limited range of 
>> data type
>> editfns.c: In function 'Fuser_real_uid':
>> editfns.c:1325: warning: comparison is always false due to limited range of 
>> data type
>> editfns.c:1325: warning: comparison is always false due to limited range of 
>> data type
>
>These and other similar warnings seem all to come from the use of
>MOST_POSITIVE_FIXNUM and MOST_NEGATIVE_FIXNUM.  Do these warnings go
>away if you modify those two macros as below?
>
>#define MOST_NEGATIVE_FIXNUM   - ((EMACS_INT) (1 << (VALBITS - 1)))
>#define MOST_POSITIVE_FIXNUM   ((EMACS_INT) (1 << (VALBITS - 1) - 1))

No, those definitions are wrong: on amd64, EMACS_INT is a long, so the
above is wrong because 1 is an int and is shifted by more than its size.

The way things are defined now, that is:
#define MOST_NEGATIVE_FIXNUM    - ((EMACS_INT) 1 << (VALBITS - 1))
#define MOST_POSITIVE_FIXNUM    (((EMACS_INT) 1 << (VALBITS - 1)) - 1)

is correct as far as I can see, because 1 is cast to long, then shifted,
which yields a long.

The reason why thos ewarnings are there is that a comparison is made
between an int (32 bits) or a short (16 bits) and a constant long (64 bits).

Such a comparison is useless, because the compiler knows that the
constant long is always bigger than the int, due to its size.  I tried
to avoid the comparison by changing the FIXNUM_OVERFLOW_P macro like
this:

#define FIXNUM_OVERFLOW_P(i) \
  (sizeof(i) >= sizeof(EMACS_INT) \
   && ((EMACS_INT)(i) > MOST_POSITIVE_FIXNUM \
       || (EMACS_INT)(i) < MOST_NEGATIVE_FIXNUM))

that is, by adding a test on sizeof at the beginning.  However, this has
no effect and the following warnings are always there:

gcc -c -D_BSD_SOURCE   -Demacs -DHAVE_CONFIG_H   -I. 
-I/home/pot/gnu/emacs-22.0.91/src -D_BSD_SOURCE  -g -O2 -Wno-pointer-sign  
editfns.c
editfns.c: In function 'Fuser_uid':
editfns.c:1317: warning: comparison is always false due to limited range of 
data type
editfns.c:1317: warning: comparison is always false due to limited range of 
data type
editfns.c: In function 'Fuser_real_uid':
editfns.c:1325: warning: comparison is always false due to limited range of 
data type
editfns.c:1325: warning: comparison is always false due to limited range of 
data type

gcc -c -D_BSD_SOURCE   -Demacs -DHAVE_CONFIG_H   -I. 
-I/home/pot/gnu/emacs-22.0.91/src -D_BSD_SOURCE  -g -O2 -Wno-pointer-sign  fns.c
fns.c: In function 'maybe_resize_hash_table':
fns.c:4684: warning: comparison is always false due to limited range of data 
type

gcc -c -D_BSD_SOURCE   -Demacs -DHAVE_CONFIG_H   -I. 
-I/home/pot/gnu/emacs-22.0.91/src -D_BSD_SOURCE  -g -O2 -Wno-pointer-sign  
process.c
process.c: In function 'Fdelete_process':
process.c:820: warning: comparison is always false due to limited range of data 
type
process.c:820: warning: comparison is always false due to limited range of data 
type
process.c:830: warning: comparison is always false due to limited range of data 
type
process.c:830: warning: comparison is always false due to limited range of data 
type
process.c: In function 'Fprocess_id':
process.c:917: warning: comparison is always false due to limited range of data 
type
process.c:917: warning: comparison is always false due to limited range of data 
type
process.c: In function 'sigchld_handler':
process.c:6441: warning: comparison is always false due to limited range of 
data type
process.c:6441: warning: comparison is always false due to limited range of 
data type

Doing like this:

#define FIXNUM_OVERFLOW_P(i) \
  ((sizeof(i) < sizeof(EMACS_INT)) ? 0 \
   : ((EMACS_INT)(i) > MOST_POSITIVE_FIXNUM \
       || (EMACS_INT)(i) < MOST_NEGATIVE_FIXNUM))

still changes nothing.  Apparently the compiler runs the second test
even if the first one fails, and so issues a warning.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]