🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gcc.bug
Article #1081

gcc-1.40.90 and volatile

#1081
From: Pierre Willard
Date: Mon, 07 Sep 1992 23:28
73 lines
2317 bytes
Two small bugs with gcc-1.40.90 (sorry, we do not have gcc-1.41 yet).

1/ When doing a post-increment of a volatile variable (in memory),
the value is fetched TWICE from memory. 

2/ A volatile qualifier for a global register variable is forgotten by
gcc. The GCC documentation says about the 'volatil' flag in a rtl :
"In a `reg' expression, it is 1 if the value is a user-level variable.
0 indicates an internal compiler temporary". This seems to imply that
for a register variable (local or global) the volatile qualifier has
no effect. Is this true ? is it the same for gcc2 ?

The following demonstrates the problems :

psi:/tmp_mnt/net/tau/home/gnu/gcc-1.40.9/gcc-sun4:cat pw.c

volatile int zzz;

void foo(void)
{
  zzz++;
}

volatile register int xxx asm("%g2");

void bar(void)
{
  xxx = 0;
  xxx++;
}

psi:/tmp_mnt/net/tau/home/gnu/gcc-1.40.9/gcc-sun4:./gcc -v -S -O pw.c
gcc version 1.40.9
 cpp -v -undef -D__GNUC__ -Dsparc -Dsun -Dunix -D__sparc__ -D__sun__ -D__unix__ -D__OPTIMIZE__ pw.c /usr/tmp/cca10252.cpp
GNU CPP version 1.40.9
 cc1 /usr/tmp/cca10252.cpp -quiet -dumpbase pw.c -O -version -o pw.s
GNU C version 1.40.9 (sparc) compiled by CC.
default target switches: -mfpu -mepilogue
psi:/tmp_mnt/net/tau/home/gnu/gcc-1.40.9/gcc-sun4:cat pw.s
gcc_compiled.:
.text
	.align 4
.global _foo
	.proc 1
_foo:
	!#PROLOGUE# 0
	save %sp,-80,%sp
	!#PROLOGUE# 1
	sethi %hi(_zzz),%g1
	ld	[%g1+%lo(_zzz)],%o0
	ld	[%g1+%lo(_zzz)],%o0    <------ this one is useless
	add %o0,1,%o0
	st	%o0,[%g1+%lo(_zzz)]
	ret
	restore
	.align 4
.global _bar
	.proc 1
_bar:
	!#PROLOGUE# 0
	save %sp,-80,%sp
	!#PROLOGUE# 1
	mov 0,%g2
	mov 1,%g2      <----- gcc has changed xxx++ into xxx=1 (with xxx volatile)!
	ret
	restore
.global _zzz
.common _zzz,8,"bss"
psi:/tmp_mnt/net/tau/home/gnu/gcc-1.40.9/gcc-sun4:

Please give me your comments
Regards
Pierre Willard
Technical Details
Message-ID: <9209072328.AA20931@_la.tce.com>
Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!la.tce.COM!pierre

Show Full Headers
Complete Article Headers
Newsgroups: gnu.gcc.bug
Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!la.tce.COM!pierre
From: pierre@la.tce.COM (Pierre Willard)
Subject: gcc-1.40.90 and volatile
Message-ID: <9209072328.AA20931@_la.tce.com>
Sender: gnulists@ai.mit.edu
Reply-To: pierre@la.tce.com
Organization: GNUs Not Usenet
Distribution: gnu
Date: Mon, 7 Sep 1992 23:28:51 GMT
Approved: bug-gcc@prep.ai.mit.edu
Lines: 74