Subject: port-i386/8364: egcs optimizer bug on i386 tickled by rwho
To: None <gnats-bugs@gnats.netbsd.org>
From: None <John.P.Darrow@wheaton.edu>
List: netbsd-bugs
Date: 09/09/1999 14:35:54
>Number: 8364
>Category: port-i386
>Synopsis: egcs optimizer bug on i386 tickled by rwho
>Confidential: no
>Severity: serious
>Priority: high
>Responsible: port-i386-maintainer (NetBSD/i386 Portmaster)
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Thu Sep 9 14:35:01 1999
>Last-Modified:
>Originator: John Darrow
>Organization:
Computing Services
Wheaton College, Wheaton, IL
>Release: from the egcs integration to at least current-19990909, including 1.4*
>Environment:
System: NetBSD jdarrowp5.wheaton.edu 1.4K NetBSD 1.4K (JDARROWP5) #0: Thu Sep 9 13:13:41 CDT 1999 jdarrow@jdarrowp5.wheaton.edu:/var/src/sys/arch/i386/compile/JDARROWP5 i386
>Description:
egcs on i386 has an optimizer bug which happens to get hit by rwho.
(Id: NetBSD: rwho.c,v 1.11 1998/12/19 21:52:00 christos Exp )
rwho uses an idle counter mp->myidle which is originally in seconds.
It then divides it by 60 (rwho.c line 168) to get a counter in minutes.
If the counter is >= 60, it prints out in hours and minutes, the
former being mp->myidle / 60 (rwho.c line 174).
When -O2 is used, the optimizer somehow attempts to (mis-)combine the
two divisions by 60, resulting in strange (negative) output for the
hours part of the idle time (while the minutes remains correct).
With -O, the output is correct.
Adding a printf of mp->myidle between lines 168 and 169 somehow
"fixes" the problem, as does adding a printf of mp->myidle / 60
before line 173. Adding a simple printf of mp->myidle before 173
does not, however. Also, breaking the division in line 168 into
two divisions (say, first by 10 then by 6) also "fixes" the problem.
>How-To-Repeat:
[60] root@jdarrowp5:ttyp4:/var/src/usr.bin/rwho:# !make
make cleandir depend CFLAGS=-O2 all
rm -f a.out [Ee]rrs mklog core *.core rwho rwho.o rwho.ln
rm -f rwho.cat1
rm -f .depend /var/src/usr.bin/rwho/tags
mkdep -a rwho.c
cc -O2 -c rwho.c
cc -o rwho rwho.o
nroff -Tascii -mandoc rwho.1 > rwho.cat1
[61] root@jdarrowp5:ttyp4:/var/src/usr.bin/rwho:# ./rwho -a
dlang johnh:ttyp1 Sep 9 15:32
eenke csserver2:ttyp1 Sep 9 15:37 :09
eenke csserver2:ttyp2 Sep 9 14:57 :49
eenke csserver2:ttyp3 Sep 9 14:57
eenke scilab1:ttyp1 Sep 9 12:49 -5:35
jdarrow csserver2:ttyp4 Sep 9 15:01 :09
jdarrow csserver2:ttyp8 Sep 8 21:19 -6:05
jdarrow jdarrowppp:tty02 Sep 7 23:04 :03
jdarrow jdarrowp5:ttyp1 Sep 9 13:44 :08
jdarrow jdarrowp5:ttyp2 Sep 9 13:44
jdarrow jdarrowp5:ttyp3 Sep 9 13:44 -4:01
jdarrow jdarrowp5:ttyp4 Sep 9 13:44
jdarrow jdarrowp5:ttyp5 Sep 9 13:44 -4:01
johnh csserver2:ttyp6 Sep 9 14:25 -3:20
johnh johnh:ttyp2 Aug 23 07:14 -3:34
johnh johnh:ttyp3 Sep 2 15:04 :22
johnh johnh:ttyp5 Sep 9 14:20 -3:20
mangliss johnh:ttyp6 Sep 9 15:06
mangliss johnh:ttyp8 Sep 9 15:12 :15
peapen johnh:ttyp4 Sep 9 15:06
[62] root@jdarrowp5:ttyp4:/var/src/usr.bin/rwho:# make cleandir depend CFLAGS=-O
all
rm -f a.out [Ee]rrs mklog core *.core rwho rwho.o rwho.ln
rm -f rwho.cat1
rm -f .depend /var/src/usr.bin/rwho/tags
mkdep -a rwho.c
cc -O -c rwho.c
cc -o rwho rwho.o
nroff -Tascii -mandoc rwho.1 > rwho.cat1
[63] root@jdarrowp5:ttyp4:/var/src/usr.bin/rwho:# ./rwho -a
dlang johnh:ttyp1 Sep 9 15:32
eenke csserver2:ttyp1 Sep 9 15:37 :09
eenke csserver2:ttyp2 Sep 9 14:57 :49
eenke csserver2:ttyp3 Sep 9 14:57
eenke scilab1:ttyp1 Sep 9 12:49 2:35
jdarrow csserver2:ttyp4 Sep 9 15:01 :09
jdarrow csserver2:ttyp8 Sep 8 21:19 3:05
jdarrow jdarrowppp:tty02 Sep 7 23:04 :03
jdarrow jdarrowp5:ttyp1 Sep 9 13:44 :08
jdarrow jdarrowp5:ttyp2 Sep 9 13:44
jdarrow jdarrowp5:ttyp3 Sep 9 13:44 2:01
jdarrow jdarrowp5:ttyp4 Sep 9 13:44
jdarrow jdarrowp5:ttyp5 Sep 9 13:44 2:01
johnh csserver2:ttyp6 Sep 9 14:25 1:20
johnh johnh:ttyp2 Aug 23 07:14 1:34
johnh johnh:ttyp3 Sep 2 15:04 :22
johnh johnh:ttyp5 Sep 9 14:20 1:20
mangliss johnh:ttyp6 Sep 9 15:06
mangliss johnh:ttyp8 Sep 9 15:12 :15
peapen johnh:ttyp4 Sep 9 15:06
>Fix:
Workarounds: compile with -O, or change one of the divisions into
two operations. Fix not yet known.
>Audit-Trail:
>Unformatted: