This is the mail archive of the gcc-patches@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: Volatile MEMs in statement expressions and functions inlined as trees


On Dec  6, 2001, Linus Torvalds <torvalds@transmeta.com> wrote:

> In article <or4rn9fqka.fsf@free.redhat.lsd.ic.unicamp.br> you write:
>> 
>> volatile int *p, *q, r;
>> 
>> void foo() {
>> *p = *q = r; // don't load *p back
>> }

> Does this still load off "q"?

Yup.  I'm pretty sure I read somewhere that this should be done, but I
can't find the reference now and, in fact, some reading of the C99 and
C++ Standards seem to imply that *q shouldn't be re-loaded.

> 	*q = r;		// read 'r' just once, write to 'q'
> 	*p = *q;	// read 'q' again, write it to 'p'

> (the latter seems to be what at least older versions of gcc reads into
> it). 

Yup.  Perhaps the `somewhere' where I read it was some GCC
documentation or source file :-(

[checks]

Yeah, I see this in expr.c:

      /* If target is volatile, ANSI requires accessing the value
	 *from* the target, if it is accessed.  So make that happen.
	 In no case return the target itself.  */
      if (! MEM_VOLATILE_P (target) && want_value)
	dont_return_target = 1;

Do we want to change this?  Perhaps some older C standard imposed this
requirement?

-- 
Alexandre Oliva   Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
Red Hat GCC Developer                  aoliva@{cygnus.com, redhat.com}
CS PhD student at IC-Unicamp        oliva@{lsd.ic.unicamp.br, gnu.org}
Free Software Evangelist    *Please* write to mailing lists, not to me


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