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


Fergus Henderson <fjh@cs.mu.OZ.AU> writes:

| On 01-May-2003, Richard Henderson <rth@redhat.com> wrote:
| > On Thu, May 01, 2003 at 08:47:03PM -0700, Geoff Keating wrote:
| > > For instance, at program startup (in this case) the abstract machine
| > > says the string contains a particular value, and how can it do that if
| > > it is optimized away?
| > 
| > Ok, I'll play your game.  By the as-if rule, it *does*
| > have that value.  Any time the program cares to check
| > that'll be true.
| 
| The "as-if" rule (C99 5.1.2.3, C++98 1.9) only applies to non-volatile
| objects.

I disagree.  See below.

| The part of C and C++ standards which defines the "as-if"
| rule specifically requires implementations to not optimize away accesses
| to volatile variables (C99 5.1.2.3, C++98 1.9 paragraphs 1 and 7), and

C++98 1.9/1:

  The semantic descriptions in this International Standard define a
  parameterized nondeterministic abstract machine. This International
  Standard places no requirement on the structure of conforming
  implementa-tions. In particular, they need not copy or emulate the
  structure of the abstract machine. Rather, conform-ing
  implementations are required to emulate (only) the observable
  behavior of the abstract machine as explained below.5)

There is nothing there that prevents the compiler to apply the "as-if"
rule to to volatile objects.  The only thinr that is required is to
emulate the observable behavuour".  The implementation is free to
implement whatever it likes  as far as the observable behaviour is
preserved.  The note 5) specifically says:

  This provision is sometimes called the  as-if  rule, because an
  *implementation is free to disregard any requirement of this
  International Standard as long as the result is as if the
  requirement had been obeyed, as far as can be determined from the
  observable behavior of the program*. For instance, an actual
  implementation need not evaluate part of an expression if it can
  deduce that its value is not used and that no side effects affecting
  the observable behavior of the program are produced.
 

-- Gaby


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