[LLVMdev] Why "I = ++I" instead of "++I" in COFFDump.cpp ?
Richard
legalize at xmission.com
Tue Apr 8 09:39:44 PDT 2014
In article <CAOfiQq=gtrW-qHLLn-5bfmwZ6Qr4wv3mi=NP78AetEOpbTJVqA at mail.gmail.com>,
Richard Smith <richard at metafoo.co.uk> writes:
> On Mon, Apr 7, 2014 at 12:09 PM, Joerg Sonnenberger <joerg at britannica.bec.de
> > wrote:
>
> > It is a bug as it violates the sequence point rule. One memory location
> > shall not be modified twice.
>
>
> Not in C++11, and (probably) not in C11. The side-effect of pre-increment
> is sequenced before its value computation, and its value computation is
> sequenced before the assignment. (C++ doesn't have sequence points any
> more, and C only has them as a vestigial remnant of the pre-memory-model
> world.)
OK, still looking on how to find this in the standard.
Discussion of postfix ++ and --:
5.2 Postfix expressions
5.2.6 Increment and decrement
"The value computation of the ++ expression is sequenced before
the modification of the operand object."
Discussion of prefix ++ and --:
5.3 Unary expressions
5.3.2 Increment and decrement
...doesn't say anything about sequencing
It seems that with postfix operators the reason the code in 1.9.15
("i = i++ + 1", for example) was yielding undefined behavior was because
although the value computation of postfix++ is sequenced before the
modification of the operand object (5.2.6), the standard doesn't guarantee
anything about the relative sequencing of the postfix++ modification
and the assignment of the computed rvalue to the lvalue.
So a conforming implementation could do either:
// initially i = 9
i = i++ + 1;
// 1. evalute i++ to get 9
// 2. evalute 1 to get 1
// 3. add 9 + 1 to get 10
// 4. assign 10 to i
// 5. increment i to 11
-or-
// initially i = 9
i = i++ + 1;
// 1. evalute i++ to get 9
// 2. increment i to 10
// 3. evalute 1 to get 1
// 4. add 9 + 1 to get 10
// 5. assign 10 to i
Am I getting closer?
--
"The Direct3D Graphics Pipeline" free book <http://tinyurl.com/d3d-pipeline>
The Computer Graphics Museum <http://ComputerGraphicsMuseum.org>
The Terminals Wiki <http://terminals.classiccmp.org>
Legalize Adulthood! (my blog) <http://LegalizeAdulthood.wordpress.com>
More information about the llvm-dev
mailing list