From: Mike Stump <mikestump@comcast.net>
To: Nathan Sidwell <nathan@codesourcery.com>
Cc: Mark Mitchell <mark@codesourcery.com>,
Michael Matz <matz@suse.de>,
Richard Guenther <richard.guenther@gmail.com>,
GCC Patches <gcc-patches@gcc.gnu.org>
Subject: Re: [gimple] assignments to volatile
Date: Thu, 24 Jun 2010 17:05:00 -0000 [thread overview]
Message-ID: <798730F0-AFFA-4812-AA49-E41A23A02D21@comcast.net> (raw)
In-Reply-To: <4C231176.6050501@codesourcery.com>
On Jun 24, 2010, at 1:04 AM, Nathan Sidwell wrote:
> On 06/23/10 19:36, Mike Stump wrote:
>> C++ says:
>
> C and C++ differ in their cast-to-void behaviour. In particular, in C++
> (void)obj;
> does not cause a read of obj, because no lvalue->rvalue decay occurs. This is very confusing for volatiles and incompatible with established C semantics. As such G++ will cause a read of a volatile scalar obj in these cases.
Yeah, this was one of the later changes that I groaned over when it went in, I wish the C and C++ standards people were on the same page. If they are to differ, I would not be against just making the construct an error, to prohibit people from making any use of a semantic that isn't the same in both languages. I know the status quo is to just conform to the C semantic, and I didn't argue or object to that; it's just an unfortunate position to be in. However, since we went in that direction, I wish people would formulate a change for the C++ language consistent with that and get that in, say, in the name of C compatibility.
> In C++ the result of an assignment is an lvalue. It is not in C.
>
>> You can't just willy nilly change this:
>>
>> int i, j, k;
>> void foo(int&j) {
>> foo(i = k);
>> }
>>
>> can sense if you get it right or not. Add a volatile on i, and you discover, you can't just change this as you see fit, in particular, not in the way you all seem to want, which is just plain wrong.
>
> I do not know what you are saying here. Making (just) i volatile will render your code example ill-formed.
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:
volatile int i, j, k;
volatile int vi;
void foo(int j) {
foo(i = k);
}
where the value passed to foo is the value read from i, and i being volatile, would mean a read of i.
>> Further, C says:
>>
>> An assignment expression has the value of the left operand after the assignment
>>
>> Now, this is pretty plain, the value is the left operand. They choose this wording as they didn't want the return value to be a modifiable lvalue. I concede there is enough wiggle room here to confuse users and give implementors enough latitude to try and claim they are following the standard, but really, the return value is the valuer of the left operand, if it weren't, the standard would not say it was. It could have said, the value is the value that was stored in the left operand, or the value is the right operand after conversion to the type of the left operand, or a host of other possibilities.
>
> Are you saying that in C, both
>
> (void)obj;
> and
> (void)(obj = value);
>
> should behave the same wrt the behaviour of reads from a volatile obj? I thought there was consensus that they should not.
Technically, I was arguing against the dropping of the re-read of vobj in the a = vobj = c; case. I believe doing so would cause g++ to violate the C++ language standard.
next prev parent reply other threads:[~2010-06-24 15:42 UTC|newest]
Thread overview: 81+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-06-21 12:44 Nathan Sidwell
2010-06-21 13:26 ` Richard Guenther
2010-06-21 13:55 ` Michael Matz
2010-06-21 14:07 ` Richard Guenther
2010-06-21 14:09 ` Nathan Sidwell
2010-06-21 14:17 ` Michael Matz
2010-06-21 14:19 ` Richard Guenther
2010-06-21 14:53 ` Michael Matz
2010-06-21 14:17 ` IainS
2010-06-21 14:24 ` Michael Matz
2010-06-21 14:50 ` Nathan Sidwell
2010-06-21 15:24 ` Michael Matz
2010-06-22 11:36 ` Dave Korn
2010-06-23 20:16 ` Mike Stump
2010-06-24 11:51 ` Michael Matz
2010-06-21 15:24 ` Nathan Sidwell
2010-06-21 15:46 ` Michael Matz
2010-06-22 15:37 ` Mark Mitchell
2010-06-22 15:37 ` Jakub Jelinek
2010-06-22 15:57 ` Paul Koning
2010-06-22 15:47 ` Michael Matz
2010-06-22 15:58 ` Mark Mitchell
2010-06-23 11:38 ` Nathan Sidwell
2010-06-23 14:05 ` Mark Mitchell
2010-06-23 14:06 ` Michael Matz
2010-06-23 16:00 ` Richard Guenther
2010-06-23 16:25 ` Paul Koning
2010-06-23 17:13 ` Mark Mitchell
2010-06-23 19:16 ` Mike Stump
2010-06-24 10:22 ` Mark Mitchell
2010-06-24 15:53 ` Mike Stump
2010-06-24 16:00 ` Mark Mitchell
2010-06-24 19:37 ` Mike Stump
2010-06-25 9:37 ` Nathan Sidwell
2010-06-25 19:06 ` Mike Stump
2010-06-25 21:33 ` Mark Mitchell
2010-06-26 9:35 ` Mike Stump
2010-06-26 10:18 ` Mark Mitchell
2010-06-26 12:18 ` Richard Guenther
2010-06-26 19:52 ` Michael Matz
2010-06-26 19:57 ` Mark Mitchell
2010-06-26 20:08 ` Michael Matz
2010-06-26 22:13 ` Mark Mitchell
2010-06-28 9:20 ` Nathan Sidwell
2010-06-28 9:27 ` Nathan Sidwell
2010-06-26 10:20 ` Richard Kenner
2010-06-28 9:52 ` Nathan Sidwell
2010-06-30 22:52 ` Mike Stump
2010-07-05 8:59 ` Nathan Sidwell
2010-07-09 5:27 ` Mike Stump
2010-07-09 7:22 ` Nathan Sidwell
2010-07-16 8:10 ` Nathan Sidwell
2010-07-16 15:20 ` Mark Mitchell
2010-07-19 8:41 ` Nathan Sidwell
2010-08-13 9:56 ` Nathan Sidwell
2010-08-18 15:32 ` Mark Mitchell
2010-08-18 16:18 ` Richard Guenther
2010-08-18 18:04 ` Mike Stump
2010-08-19 11:11 ` Nathan Sidwell
2010-08-20 4:22 ` Mark Mitchell
2010-08-20 16:59 ` Mike Stump
2010-08-20 18:00 ` H.J. Lu
2010-08-20 18:33 ` Nathan Sidwell
2010-06-25 9:20 ` Nathan Sidwell
2010-06-24 10:23 ` Nathan Sidwell
2010-06-24 17:05 ` Mike Stump [this message]
2010-06-24 17:29 ` Paul Koning
2010-06-25 9:26 ` Nathan Sidwell
2010-06-25 18:20 ` Mike Stump
2010-06-28 8:49 ` Nathan Sidwell
2010-07-01 1:02 ` Mike Stump
2010-07-05 9:02 ` Nathan Sidwell
2010-07-09 5:14 ` Mike Stump
2010-07-09 7:20 ` Nathan Sidwell
2010-06-22 15:56 ` Paul Koning
2010-06-22 12:08 ` Nathan Sidwell
2010-06-22 12:25 ` Richard Guenther
2010-06-22 13:12 ` Michael Matz
2010-06-22 13:54 ` Nathan Sidwell
2010-06-22 15:21 ` Michael Matz
2010-06-22 16:12 ` Joseph S. Myers
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=798730F0-AFFA-4812-AA49-E41A23A02D21@comcast.net \
--to=mikestump@comcast.net \
--cc=gcc-patches@gcc.gnu.org \
--cc=mark@codesourcery.com \
--cc=matz@suse.de \
--cc=nathan@codesourcery.com \
--cc=richard.guenther@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).