This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: GCC warnings for unused global variables


On Fri, May 02, 2003 at 09:42:23AM -0700, Joe Buck wrote:
> On Fri, May 02, 2003 at 06:00:30PM +0200, Gabriel Dos Reis wrote:
> > | Because, since the object is volatile, it may affect the program in
> > | ways unknown to the compiler.
> > 
> > This is my favorite peeve against the definition of "volatile".
> > Does an alpha ray fired from Centauri count as a "way unknown to the
> > compiler"?
> 
> This is a much better example than you thought it was.  The answer is
> "yes".  Alpha particles are a major source of soft errors; they can
> spontaneously change the value that is stored in RAM.  Duplicated
> reads can't be eliminated because they might miss the change caused
> by the alpha particle.  A memory test might be written in C with
> a big volatile array, and one of the things it would be looking for
> is effects caused by alpha particles.

Thanks!  I hadn't thought of this kind of "unknown to the compiler" effect
until now.  What I was missing was that the "unknown effect" needn't
necessarily be deterministic, IOW just because the compiler can *prove*
that a variable isn't deterministically accessible doesn't mean that no
"unknown" accesses happen.  So now I'm convinced that in

void foo(void)
{
	int volatile bar = 42;
	int baz;
	baz = bar - bar;
}

there is no guarantee that baz == 0.  And that GCC may not play smarty-pants
even here.

Hmm, I seem to recall a similar thread last year or so...

http://gcc.gnu.org/ml/gcc/1998-06/msg00098.html (Hmm, no, too old.)

Here we go: [PATCH] C undefined behavior fix

http://gcc.gnu.org/ml/gcc/2002-01/msg00808.html is part of
http://gcc.gnu.org/ml/gcc/2002-01/msg00031.html

> (Of course, an alpha particle can't make it through the atmosphere,
> so you'll need to pick some other particle or photon type).

But IIRC alpha particles do (or did) come out of weird isotopes in the
ceramic casing around DRAM chips.

bernd


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]