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: [gimple] assignments to volatile


On Jun 27, 2010, at 11:28 PM, Nathan Sidwell wrote:
> On 06/25/10 17:41, Mike Stump wrote:
>> On Jun 24, 2010, at 11:35 PM, Nathan Sidwell wrote:
>>> On 06/24/10 16:42, Mike Stump wrote:
>>> 
>>>> Sorry for not expounding.  I thought it would be obvious I was talking about well formed code...  First case would be something like:
>>>> 
>>>> volatile int i, j, k;
>>>> volatile int vi;
>>>> void foo(volatile int&   j) {
>>>>   foo(i = k);
>>>> }
>>>> 
>>>> here, we need to bind j to the address of i.  The second case is something like:
>>> 
>>> Correct.  The patch does not change this behaviour -- the C++ front end already has to explicitly break out the lvalue from the assignment to conform to the semantics of TREEs.  The current G++ behaviour is not to re-read the assigned-to value.
>> 
>> g++ seems not to share your position:
>> 
>> 	movl	_i, %eax
>> 	movl	%eax, (%esp)
>> 
>> volatile int i, j, k;
>> volatile int vi;
>> void foo(int j) {
>>   foo(i = k);
>> }
>> 
>> GNU C++ (GCC) version 4.6.0 20100620 (experimental) [trunk revision 161045] (x86_64-apple-darwin10)
>> 	compiled by GNU C version 4.2.1 (Apple Inc. build 5659), GMP version 5.0.1
>> 
>> ?  Certainly I must misunderstand something, can you spot it?
> 
> You have changed the testcase to be passing by value from passing by reference.  Why do you think those would be equivalent?

The read happens when the the object referred to by the reference is accessed:

volatile int i, j;
int x, data, expr, k;

static inline void foo(volatile int &r) {
  int fetch = r;
}

int main() {
  foo(i=k);
}

	movl	_k, %eax
	movl	%eax, _i
	movl	_i, %eax

here, i is re-read.  Here, g++ in fact does re-read the assigned to value.


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