* FIXNUM_OVERFLOW_P on amd64
@ 2006-12-04 11:48 Francesco Potorti`
2006-12-04 15:01 ` Stefan Monnier
0 siblings, 1 reply; 3+ messages in thread
From: Francesco Potorti` @ 2006-12-04 11:48 UTC (permalink / raw)
On gcc (GCC) 4.1.2 20061028 (prerelease) (Debian 4.1.1-19)
I get this:
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
The relevant line is:
return make_fixnum_or_float (geteuid ());
which expands to:
return (((long)(geteuid ()) > (((long) 1 << ((64 - 3) - 1)) - 1)
|| (long) (geteuid ()) < - ((long) 1 << ((64 - 3) - 1)))
? make_float (geteuid ())
: (((long) ((long)(geteuid ()))) << 3));
in lisp.h:
#define make_fixnum_or_float(val) \
(FIXNUM_OVERFLOW_P (val) \
? make_float (val) \
: make_number ((EMACS_INT)(val)))
#define FIXNUM_OVERFLOW_P(i) \
((EMACS_INT)(i) > MOST_POSITIVE_FIXNUM \
|| (EMACS_INT) (i) < MOST_NEGATIVE_FIXNUM)
#define MOST_POSITIVE_FIXNUM (((EMACS_INT) 1 << (VALBITS - 1)) - 1)
So the problem apparently is that gcc realises that taking geteuid(),
stretching it to long and then comparing it with something bigger that
what geteuid() possibly can be is a no-op. This is what is intended, in
fact. To remove the warning, I tried to change the definition of
FIXNUM_OVERFLOW_P in lisp.h by adding a precondition like this:
#define FIXNUM_OVERFLOW_P(i) \
(sizeof(i) >= sizeof(EMACS_INT) \
&& ((EMACS_INT)(i) > MOST_POSITIVE_FIXNUM \
|| (EMACS_INT)(i) < MOST_NEGATIVE_FIXNUM))
But nothing changed: the warning is still there. While trying to find a
way to solve the problem, I realised that the make_fixnum_or_float is a
macro doing multiple evaluations of its argument, and editfns.c calls it
with a function call as an argument, which is generally not a good thing.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: FIXNUM_OVERFLOW_P on amd64
2006-12-04 11:48 FIXNUM_OVERFLOW_P on amd64 Francesco Potorti`
@ 2006-12-04 15:01 ` Stefan Monnier
2006-12-04 16:12 ` Francesco Potorti`
0 siblings, 1 reply; 3+ messages in thread
From: Stefan Monnier @ 2006-12-04 15:01 UTC (permalink / raw)
Cc: Emacs developers
> 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
[...]
> So the problem apparently is that gcc realises that taking geteuid(),
> stretching it to long and then comparing it with something bigger that
> what geteuid() possibly can be is a no-op. This is what is intended, in
> fact. To remove the warning, I tried to change the definition of
> FIXNUM_OVERFLOW_P in lisp.h by adding a precondition like this:
This warning is clearly wrong. The same problem happens at various places
with SINGLE_BYTE_P which is sometimes called from a macro at spots where we
happen to always know that the char is < 256 (for example).
The problem is that such constant expressions are sometimes an indication of
a programming bug, but they can also be the result of very good coding
practices, where you want to let the compiler do the optimization.
Stefan
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: FIXNUM_OVERFLOW_P on amd64
2006-12-04 15:01 ` Stefan Monnier
@ 2006-12-04 16:12 ` Francesco Potorti`
0 siblings, 0 replies; 3+ messages in thread
From: Francesco Potorti` @ 2006-12-04 16:12 UTC (permalink / raw)
Cc: Emacs developers
>
>> 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
>[...]
>> So the problem apparently is that gcc realises that taking geteuid(),
>> stretching it to long and then comparing it with something bigger that
>> what geteuid() possibly can be is a no-op. This is what is intended, in
>> fact. To remove the warning, I tried to change the definition of
>> FIXNUM_OVERFLOW_P in lisp.h by adding a precondition like this:
>
>This warning is clearly wrong. The same problem happens at various places
>with SINGLE_BYTE_P which is sometimes called from a macro at spots where we
>happen to always know that the char is < 256 (for example).
I also have many others. Most of them are related to the same macro in lisp.h.
>The problem is that such constant expressions are sometimes an indication of
>a programming bug, but they can also be the result of very good coding
>practices, where you want to let the compiler do the optimization.
Yes. Can we do anything for preventing gcc from emitting those warnings?
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2006-12-04 16:12 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-12-04 11:48 FIXNUM_OVERFLOW_P on amd64 Francesco Potorti`
2006-12-04 15:01 ` Stefan Monnier
2006-12-04 16:12 ` Francesco Potorti`
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.