[cfe-dev] Assignment expression in C++ returns its right operand (A possible bug)

John McCall rjmccall at apple.com
Fri Feb 17 01:52:31 PST 2012


On Feb 16, 2012, at 2:37 PM, Xiaolong Tang wrote:
> Note that the register value denoted by %tmp is returned, but %tmp is
> the value of the second parameter. (This does not agree with the c++
> semantics.) 
> 
> Again I am using clang version 3.0. And the revision is git-svn-id:
> https://llvm.org/svn/llvm-project/cfe/trunk@137823
> 
> If I am correct and the above problem has been fixed, can someone
> point to me the commit where the problem is fixed? If I am somehow
> wrong, can someone give me any explanation? 

As David says, it's not a problem.  You are correct that C++ semantics
say that the RHS is stored to the LHS and then the result of the
expression is the same l-value as the original LHS.  However, when
that l-value is non-volatile, we are not strictly bound by those
semantics.  In this case, it is clear that the object identified by the LHS
is not modified by this thread between the store and the load, and
any other thread modifying it would be a forbidden race condition.
Therefore, if the result of this assignment is needed as an r-value,
we can simply forward the original value (suitably truncated if the
l-value is a bitfield).

John.



More information about the cfe-dev mailing list