🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gcc.bug
Article #60

a (volatile) fetch gets compiled away.

#60
From: Bradley Kuszmaul
Date: Tue, 03 Nov 1992 15:53
62 lines
2735 bytes
I have an application that requires that a certain fetch from a memory
location not be compiled away (the fetch causes a side effect in some
hardware).  I found that with optimization turned on, the fetch is compiled
away, even if the the expression is declared (volatile) (and even if I
compile it with -fvolatile).

Contents:
 - a record of how I compiled the code
 - the code
 - the .s file showing that the fetch got compiled way.
-Bradley
---- The wallpaper ----
bradley@marley% gcc foo2.c -S -O -o foo2.s -Wall -g -v
Reading specs from /usr/local/lib/gcc-lib/sun4/2.2.2/specs
gcc version 2.2.2
 /usr/local/lib/gcc-lib/sun4/2.2.2/cpp -lang-c -v -undef -D__GNUC__=2 -Dsparc -Dsun -Dunix -D__sparc__ -D__sun__ -D__unix__ -D__sparc -D__sun -D__unix -D__OPTIMIZE__ -g -Wall foo2.c /usr/tmp/cca15000.i
GNU CPP version 2.2.2 (sparc)
 /usr/local/lib/gcc-lib/sun4/2.2.2/cc1 /usr/tmp/cca15000.i -quiet -dumpbase foo2.c -g -O -Wall -version -o foo2.s
GNU C version 2.2.2 (sparc) compiled by GNU C version 2.2.2.
foo2.c: In function `test':
foo2.c:2: warning: statement with no effect
bradley@marley% 
---- The .c file ----
void test(void) {
  (volatile)*((unsigned*)0x20000a20);
}
---- The .s file ----
gcc2_compiled.:
.stabs "/users/asd1/bradley/",100,0,0,Ltext0
.stabs "foo2.c",100,0,0,Ltext0
.text
Ltext0:
.stabs "int:t1=r1;-2147483648;2147483647;",128,0,0,0
.stabs "char:t2=r2;0;127;",128,0,0,0
.stabs "long int:t3=r1;-2147483648;2147483647;",128,0,0,0
.stabs "unsigned int:t4=r1;0;-1;",128,0,0,0
.stabs "long unsigned int:t5=r1;0;-1;",128,0,0,0
.stabs "short int:t6=r1;-32768;32767;",128,0,0,0
.stabs "long long int:t7=r1;0;-1;",128,0,0,0
.stabs "short unsigned int:t8=r1;0;65535;",128,0,0,0
.stabs "long long unsigned int:t9=r1;0;-1;",128,0,0,0
.stabs "signed char:t10=r1;-128;127;",128,0,0,0
.stabs "unsigned char:t11=r1;0;255;",128,0,0,0
.stabs "float:t12=r1;4;0;",128,0,0,0
.stabs "double:t13=r1;8;0;",128,0,0,0
.stabs "long double:t14=r1;8;0;",128,0,0,0
.stabs "void:t15=15",128,0,0,0
	.align 4
	.global _test
	.proc	020
_test:
.stabn 68,0,1,LM1
LM1:
	!#PROLOGUE# 0
	save %sp,-112,%sp
	!#PROLOGUE# 1
.stabn 68,0,3,LM2
LM2:
	ret
	restore
.stabs "test:F15",36,0,0,_test
---- That's all folks ----
Technical Details
Message-ID: <9211031553.AA25807@marley.think.com>
Path: arc1-ca.pugleaf.net!sparky!uunet!ogicse!hp-cv!sdd.hp.com!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!think.com!bradley

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!ogicse!hp-cv!sdd.hp.com!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!think.com!bradley
From: bradley@think.com (Bradley Kuszmaul)
Newsgroups: gnu.gcc.bug
Subject: a (volatile) fetch gets compiled away.
Message-ID: <9211031553.AA25807@marley.think.com>
Date: 3 Nov 92 15:53:22 GMT
Article-I.D.: marley.9211031553.AA25807
Sender: gnulists@ai.mit.edu
Distribution: gnu
Organization: GNUs Not Usenet
Lines: 62
Approved: bug-gcc@prep.ai.mit.edu