This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: C++ standards question
- From: Ian Lance Taylor <iant at google dot com>
- To: John Fine <johnsfine at verizon dot net>
- Cc: gcc-help <gcc-help at gcc dot gnu dot org>
- Date: Sun, 3 Feb 2013 21:06:01 -0800
- Subject: Re: C++ standards question
- References: <510EF1AC.6090509@verizon.net>
On Sun, Feb 3, 2013 at 3:24 PM, John Fine <johnsfine@verizon.net> wrote:
> I have a construct that the optimizer in VS2010 64-bit changes to something
> that doesn't work.
>
> I want to know whether this is a bug in the compiler or in the code being
> compiled.
>
> I would have no idea where to look in the standards document for this
> answer. I know it is off-topic (a C++ not gcc question) but this is where
> the experts are.
>
> My function takes a parameter char* p
> One of the things the function does is test and conditionally modifies a
> char pointed to through P. Something like:
>
> if ( expression of *p ) *p = '-';
>
> The optimizer changes that to the equivalent of
>
> *p = (expression of *p ) ? '-' : *p;
>
> Is that a valid optimization?
Not these days, and current GCC should not do it.
This is called a speculative store.
Oh, wait, you were asking about Visual Studio (at least, I am guessing
that that is what you mean by VS2010). Speculative stores are
disallowed by the C++11 memory model. So when VS2010 supports C++11,
it will no longer perform this optimization. That said, I am told
that Visual Studio still does not support C99 more than ten years
later, so who knows if it will ever support C++11.
Ian