This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [gimple] assignments to volatile
- From: Mike Stump <mikestump at comcast dot net>
- To: Nathan Sidwell <nathan at codesourcery dot com>
- Cc: Mark Mitchell <mark at codesourcery dot com>, Michael Matz <matz at suse dot de>, Richard Guenther <richard dot guenther at gmail dot com>, GCC Patches <gcc-patches at gcc dot gnu dot org>
- Date: Wed, 30 Jun 2010 18:02:11 -0700
- Subject: Re: [gimple] assignments to volatile
- References: <4C1F5380.1090107@codesourcery.com> <AANLkTimzBtuWYWnzMkmDyM6Y490EIwQJxaDI_higMvJs@mail.gmail.com> <Pine.LNX.4.64.1006211517460.11284@wotan.suse.de> <4C20D40B.30904@codesourcery.com> <Pine.LNX.4.64.1006221721590.18619@wotan.suse.de> <4C20D891.5030506@codesourcery.com> <4C21E361.1040900@codesourcery.com> <4C220762.2060703@codesourcery.com> <025B27D1-E620-4BA2-A113-FD28747E2762@comcast.net> <4C231176.6050501@codesourcery.com> <798730F0-AFFA-4812-AA49-E41A23A02D21@comcast.net> <4C244E2C.9020900@codesourcery.com> <7F30721E-1B2E-41B7-B7BF-F66C936690D9@comcast.net> <4C2840FB.3010409@codesourcery.com>
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.