🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

1 total messages Started by Pierre Willard Mon, 07 Sep 1992 23:28
gcc-1.40.90 and volatile
#1081
Author: 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
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads