public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: volatile semantics
@ 2005-05-06  5:06 Paul Schlie
  0 siblings, 0 replies; 118+ messages in thread
From: Paul Schlie @ 2005-05-06  5:06 UTC (permalink / raw)
  To: Dale Johannesen, Nathan Sidwell, Mike Stump, gcc

> Dale Johannesen writes:
>> Nathan Sidwell wrote:
>> Also, I wonder about the following example
>>
>> int const avail = <something>
>>
>> int main() {
>>  while (*(int *)&avail == Foo ())
>>    do_something();
>>  return 0;
>> }
>>
>> Seeing through the const-stripping cast is a useful optimization.
>
> It is? Why would somebody write that?

- It shouldn't mater, GCC should simply treat the outermost cast as the
  effective definition of the qualified access path and type of the object
  referenced within this context. Although it seems very reasonable that a
  cast or parameter specification which results in any qualification being
  dropped, minimally produces a warning, just in case the dropping of the
  qualifier wasn't intended, as simply dropping a const qualifier for
  example does not warrant that object referenced is actually physically
  writable; i.e. for example a static const object may literally be stored
  in ROM, just as array/string, or structure literals may be; just as
  correspondingly dropping an objects volatile qualifier no longer warrants
  that it's logical reference will result in a physically access.

>> A further pathelogical case would be,
>>
>> int main() {
>>  while (*(int *)(volatile int *)&avail)
>>    do_something ();
>>  return 0;
>> }
>>
>> What should this do, treat the volatile qualifier as sticky?
>
> IMO, no, but surely we don't have to worry about this one. Either way
> is standard conformant and the user's intent is far from clear, so whatever
> we do should be OK.

- As above, the object should likely be simply references as if an (int *),
  nothing more nothing less. With a warning that the const qualifier was
  dropped upon a cast to (volatile int *), and that volatile was dropped
  upon it's final cast to (int *).



^ permalink raw reply	[flat|nested] 118+ messages in thread
* Re: volatile semantics
@ 2005-07-23  2:15 Paul Schlie
  2005-07-23  9:50 ` Geoff Keating
  0 siblings, 1 reply; 118+ messages in thread
From: Paul Schlie @ 2005-07-23  2:15 UTC (permalink / raw)
  To: Geoffrey Keating
  Cc: D. Hugh Redelmeier, Nathan Sidwell, Dale Johannesen, Mike Stump,
	GCC Development

> Geoffrey Keating writes:
>
> int i;

- merely means: allocate and treat all references to the object as
  referencing an unqualified int object, unless re-qualified within a
  more local scope.

> without 'volatile', then this object cannot be modified unknown to the
> implementation, even if someone also writes '(*(volatile int *)&i) = 1'.

- merely means: treat the object being referenced as volatile qualified int
  object (as the standard specifies, although it may result in an undefined
  behavior, nothing more or less; as although the object may have not been
  initially declared as being volatile, the program within the context of
  this particular references has asserted that it must be treated as such,
  thereby implying it's value must be assigned, and/or presumed to have been
  possibly modified beyond the logical view of the program).

  const, volatile, and restrict are all logically equivalent in this
  regard; regardless of whether or not an object was declared as being
  originally qualified, or subsequently declared as being so within the more
  restricted scope of a function via it's parameter declaration, or single
  reference via a qualified cast.  Where although inconsistent references to
  any single object may result in an undefined behavior, it should be clear
  there's no value in attempting to rationalize any more creative less
  consistent interpretation, as it will be no more correct, and only likely
  unnecessarily complicating to both the implementation and programmer.


^ permalink raw reply	[flat|nested] 118+ messages in thread
* Re: volatile semantics
@ 2005-07-19 17:56 Paul Schlie
  2005-07-19 18:13 ` Gabriel Dos Reis
  0 siblings, 1 reply; 118+ messages in thread
From: Paul Schlie @ 2005-07-19 17:56 UTC (permalink / raw)
  To: Gabriel Dos Reis
  Cc: Mike Stump, Dale Johannesen, Nathan Sidwell, GCC Development,
	D. Hugh Redelmeier:,
	Daniel Berlin

> Gabriel Dos Reis writes:
> If by analysis, you can determine ...

The problem with this type of logic is that it leads to arbitrary
inconsistent designation of an object's reference as a function of
the breadth of the "analysis", therefore seems clearly undesirable.

Resulting in only two possibilities:

A: Treat all object references as initially declared (which isn't
   technically possible as function parameter declarations make this
   impossible to begin with, and inherently inconsistent with lvalue
   cast semantics).

B: Treat all object references as declared within their current scope,
   where the effective object declarations hierarchy looks basically
   like: <allocation-decl> [<parameter-decl> | <cast-decl>], where the
   most current represents the effective declaration of the object.

Thereby (B) represents the only tenable choice (there is no in-between).

[Which seems to be real simple to understand and abide by, regardless of
whether or not the resulting reference may specify an undefined behavior;
as the job of the compiler is to abide by the specified program, not go
out of it's way attempting to identify undefined behaviors so that it may
interject it's equally undefined inconsistent behaviors without regard to
the factual behavior that it's target would otherwise yield naturally if
it just simply warned and left well enough alone, presuming the author
desired what was specified, not something otherwise.]


^ permalink raw reply	[flat|nested] 118+ messages in thread
* Re: volatile semantics
@ 2005-07-18  1:29 Paul Schlie
  2005-07-18  6:36 ` Gabriel Dos Reis
  2005-07-18 12:11 ` Jonathan Wakely
  0 siblings, 2 replies; 118+ messages in thread
From: Paul Schlie @ 2005-07-18  1:29 UTC (permalink / raw)
  To: Mark Mitchell; +Cc: Daniel Berlin, Gabriel Dos Reis, D. Hugh Redelmeier, gcc

> Note that I'm explicitly not taking a position on what the standard says.
> The standard is notoriously incomplete with respect to object model issues,
> including volatility, so I think that trying particularly hard to parse its
> words in this area is probably not a good use of time for people trying to
> build a real-world compiler. Creating DRs is more useful than trying to read
> the tea leaves.
>
> Clearly, the analogous rule does not make sense for "const" in that a "const"
> object can never be modified; in particular, if the compiler can prove that
> "*x = 3" is an attempt to modify an object whose dynamic type is "const int",
> then it can replace that with a call to "kill (SIGSEGV)", if it likes; this
> is unquestionably undefined behavior.

With all due respect, unless there is an explicit reference in the standard
to contradict it's clearly stated requirement that an object's qualified
lvalue ("locator value") designates the object being referenced, all
interpretations to the contrary are at best presumptuous, regardless of
whether or not it's generalized behavior may be indeterminate.

(but regardless, at least things are successively approximating "correct")


^ permalink raw reply	[flat|nested] 118+ messages in thread
* Re: volatile semantics
@ 2005-07-17 17:58 Paul Schlie
  0 siblings, 0 replies; 118+ messages in thread
From: Paul Schlie @ 2005-07-17 17:58 UTC (permalink / raw)
  To: Richard Henderson
  Cc: Nathan Sidwell, D. Hugh Redelmeier, Gabriel Dos Reis,
	Daniel Berlin, gcc, Joseph S. Myers, Dale Johannesen, Mike Stump,
	jsm

> I did see Ian's summary,
>
>  http://gcc.gnu.org/ml/gcc/2005-07/msg00714.html
>
> wherein he ascribed the semantics of the volatile qualifier to the
> access, and not to the object.  I agree with his description completely,
> as I believe it embodies the intuition that C programmers have used
> wrt these qualifiers since forever.
>
> So the answers to the "deleteable" questions above are no, no, yes.
> 
> And it's probably a one-line bug in our "can this cast be removed"
> function.

- or even more consistently: simply warn, and treat as specified in all
  cases. (as there's no value to exceptions otherwise)


^ permalink raw reply	[flat|nested] 118+ messages in thread
* volatile semantics
@ 2005-05-03  8:41 Mike Stump
  2005-05-03  8:52 ` Paolo Bonzini
                   ` (4 more replies)
  0 siblings, 5 replies; 118+ messages in thread
From: Mike Stump @ 2005-05-03  8:41 UTC (permalink / raw)
  To: Gcc Mailing List

int avail;
int main() {
   while (*(volatile int *)&avail == 0)
     continue;
   return 0;
}


Ok, so, the question is, should gcc produce code that infinitely  
loops, or should it be obligated to actually fetch from memory?   
Hint, 3.3 fetched.


I get:

L6:
         b L6

on mainline and 4.0.

^ permalink raw reply	[flat|nested] 118+ messages in thread

end of thread, other threads:[~2005-07-25 23:08 UTC | newest]

Thread overview: 118+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-05-06  5:06 volatile semantics Paul Schlie
  -- strict thread matches above, loose matches on Subject: below --
2005-07-23  2:15 Paul Schlie
2005-07-23  9:50 ` Geoff Keating
2005-07-23 11:39   ` Paul Schlie
2005-07-23 11:44   ` Paul Schlie
2005-07-19 17:56 Paul Schlie
2005-07-19 18:13 ` Gabriel Dos Reis
2005-07-19 18:32   ` Paul Schlie
2005-07-18  1:29 Paul Schlie
2005-07-18  6:36 ` Gabriel Dos Reis
2005-07-18 11:20   ` Paul Schlie
2005-07-18 12:12     ` Paolo Bonzini
2005-07-18 12:17     ` Paul Schlie
2005-07-18 12:27       ` Gabriel Dos Reis
2005-07-18 13:27         ` Paul Schlie
2005-07-18 15:47           ` D. Hugh Redelmeier
2005-07-18 12:24     ` Gabriel Dos Reis
2005-07-18 12:11 ` Jonathan Wakely
2005-07-18 12:31   ` Paul Schlie
2005-07-17 17:58 Paul Schlie
2005-05-03  8:41 Mike Stump
2005-05-03  8:52 ` Paolo Bonzini
2005-05-03  9:53 ` Giovanni Bajo
2005-05-03 14:31 ` Dave Korn
2005-05-03 14:41 ` Nathan Sidwell
2005-05-03 17:04   ` Dale Johannesen
2005-05-03 18:03     ` Nathan Sidwell
2005-05-03 18:32       ` Paul Koning
2005-05-03 18:37         ` Dale Johannesen
2005-05-11 23:01         ` Geoffrey Keating
2005-05-12 14:46           ` Paul Koning
2005-05-03 18:35       ` Dale Johannesen
2005-05-03 18:54         ` Nathan Sidwell
2005-05-03 19:25           ` Dale Johannesen
2005-05-04  8:18             ` Nathan Sidwell
2005-05-04 10:23               ` Andrew Haley
2005-05-04 11:30                 ` Gabriel Dos Reis
2005-05-04 17:59                   ` Dale Johannesen
2005-05-04 18:01                     ` Paul Koning
2005-05-04 19:49                     ` Nathan Sidwell
2005-07-16 16:51     ` D. Hugh Redelmeier
2005-07-16 16:56       ` Daniel Berlin
2005-07-16 17:26         ` Nathan Sidwell
2005-07-16 17:32           ` Daniel Berlin
2005-07-16 18:35             ` Nathan Sidwell
2005-07-16 20:35               ` Daniel Berlin
2005-07-16 21:29                 ` Gabriel Dos Reis
2005-07-16 21:41                   ` Daniel Berlin
2005-07-16 21:59                     ` Gabriel Dos Reis
2005-07-16 21:07             ` Gabriel Dos Reis
2005-07-16 19:20         ` D. Hugh Redelmeier
2005-07-16 21:10           ` Gabriel Dos Reis
2005-07-16 20:52         ` Gabriel Dos Reis
2005-07-16 21:07           ` Daniel Berlin
2005-07-16 21:24             ` Gabriel Dos Reis
2005-07-16 21:30               ` Daniel Berlin
2005-07-16 22:19                 ` Gabriel Dos Reis
2005-07-16 21:36               ` Daniel Berlin
2005-07-16 22:06                 ` Gabriel Dos Reis
2005-07-16 22:17                   ` Daniel Berlin
2005-07-16 22:25                     ` Gabriel Dos Reis
2005-07-19  7:27                       ` Kai Henningsen
2005-07-19  9:25                         ` Gabriel Dos Reis
2005-07-16 22:34               ` D. Hugh Redelmeier
2005-07-16 22:57                 ` Gabriel Dos Reis
2005-07-17  1:37                   ` D. Hugh Redelmeier
2005-07-17  2:24                     ` Gabriel Dos Reis
2005-07-17  2:36                       ` Daniel Berlin
2005-07-17  3:08                         ` Gabriel Dos Reis
2005-07-17  4:32                           ` Michael Veksler
2005-07-17  5:19                           ` Michael Veksler
2005-07-17  5:31                             ` Gabriel Dos Reis
2005-07-17  7:33                               ` Michael Veksler
2005-07-17 14:33                             ` Daniel Berlin
2005-07-17 15:30                               ` Michael Veksler
2005-07-17  7:53                           ` Andrew Pinski
2005-07-17 11:41                             ` Gabriel Dos Reis
2005-07-17  7:40                       ` D. Hugh Redelmeier
2005-07-17 11:50                         ` Gabriel Dos Reis
2005-07-18 19:30                           ` Mike Stump
2005-07-18 20:05                             ` Gabriel Dos Reis
2005-07-17 15:45                         ` Richard Henderson
2005-07-17 16:04                           ` Nathan Sidwell
2005-07-17 16:18                             ` Richard Henderson
2005-07-17 16:54                               ` Gabriel Dos Reis
2005-07-17 16:06                           ` Falk Hueffner
2005-07-17 16:18                           ` Ian Lance Taylor
2005-07-17 16:44                             ` Richard Henderson
2005-07-17 12:49                       ` Joseph S. Myers
2005-07-17  2:27                     ` Daniel Berlin
2005-07-17  3:14                       ` Gabriel Dos Reis
2005-07-17  3:27                         ` Daniel Berlin
2005-07-17 20:34                           ` Mark Mitchell
2005-07-17  4:38                         ` D. Hugh Redelmeier
2005-07-17  5:27                           ` Gabriel Dos Reis
2005-07-18 13:13                           ` Gerald Pfeifer
2005-07-17  7:54                       ` D. Hugh Redelmeier
2005-07-17 10:11               ` Andrew Haley
2005-07-17 12:03                 ` Gabriel Dos Reis
2005-07-16 17:33       ` Andrew Haley
2005-07-16 17:53         ` Daniel Berlin
2005-07-17  8:25           ` Ian Lance Taylor
2005-07-22 23:20             ` Geoffrey Keating
2005-07-22 23:33               ` Ian Lance Taylor
2005-07-23  1:28                 ` Geoff Keating
2005-07-23  2:59                   ` Gabriel Dos Reis
2005-07-23  9:50                     ` Geoff Keating
2005-07-23  6:03                   ` Ian Lance Taylor
2005-07-23 16:03                   ` Mike Stump
2005-07-16 19:05         ` Dale Johannesen
2005-07-16 21:17           ` Gabriel Dos Reis
2005-07-22 23:20       ` Geoffrey Keating
2005-07-25 23:08         ` Olivier Galibert
2005-05-06  0:45   ` Kai Henningsen
2005-05-06  1:42     ` Paul Koning
2005-05-06  2:04     ` Gabriel Dos Reis
2005-05-06  2:57     ` Dale Johannesen
2005-05-03 21:19 ` Thorsten Glaser

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).