From 7860526668339925180
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,7522e5259f7267d6
X-Google-Attributes: gidf78e5,public
From: jpotter@falcon.lhup.edu (John Potter)
Subject: Re: x = y = z;  Undefined?
Date: 2000/01/18
Message-ID: <38838d77.27187570@news.csrlink.net>#1/1
X-Deja-AN: 574295189
X-NNTP-Posting-Host: 209.173.92.112
Approved: stephen.clamage@sun.com (comp.std.c++)
References: <MPG.12ddaa92533ae9679896a6@news.supernews.com> <t7so0bqea7.fsf@calumny.jyacc.com> <3876254a.30903561@news.csrlink.net> <derobert-9FC87E.01591309012000@news.erols.com> <3879ca08.3142429@news.csrlink.net> <derobert-8223E1.23372510012000@news.erols.com> <387b3c32.7816532@news.csrlink.net> <t7d7r8xyxm.fsf@calumny.jyacc.com> <387bc96e.43976982@news.csrlink.net> <t7so03w0xj.fsf@calumny.jyacc.com> <387dc78f.4864697@news.csrlink.net> <derobert-B813E8.01462317012000@news.erols.com>
X-UID: 0000000002
X-Status: $$$$
X-Trace: newscene.newscene.com 948160885 209.173.92.112 (Mon, 17 Jan 2000 20:01:25 CST)
Organization: Newscene Public Access Usenet News Service (http://www.newscene.com/)
NNTP-Posting-Date: Mon, 17 Jan 2000 20:01:25 CST
Newsgroups: comp.std.c++
Originator: clamage@taumet


On Mon, 17 Jan 2000 20:57:19 CST, Anthony DeRobertis
<derobert@erols.com> wrote:

: In article <387dc78f.4864697@news.csrlink.net>, jpotter@falcon.lhup.edu 
: (John Potter) wrote:
: 
: >For the given two machine instructions, I think I am safe in that.  They
: >both modify the same variable with the second using the result of the
: >first.  Without knowing that there is no sequence point, the
: >instructions may not be reversed.
: 
: Correct. But if a compiler were to actually use the sequence points to 
: determine how it can schedule instructions, it would not notice that 
: dependency.

The dependency is a value dependency.  Your example:

   (i1 = i2) += i3; // undefined, generates
      or i1,i2,i2
      add i1,i1,i3

My counter example:

   i4 = (i1 = i2) + i3; // well defined, generates
      or i1,i2,i2
      add i4,i1,i3

Same two instructions with the same value dependency.  The second
instruction depends upon the value of the first instruction, not
upon where it was put.

: There is no reason to expect a compiler to check for a store conflict 
: like that inside of one sequence point.

We agree.  Without checking the store conflict and noting that this is
undefined behavior which allows anything, the two intstructions may not
be reversed because of the value dependency.

Going to a simpler machine:

   mov bx,i2;  i1 is in bx and will be stored later
   mov ax,bx
   add ax,i3
   mov i4,ax
   mov i1,bx;  sequence point, so store it

This is a valid translation which produces two correct answers.  To go
back to the original, change i4 to i1.  Wrong answer with code which
could only be noticed by observing the store conflict which is not
required.

This is the kind of example I desired.  It demonstrates undefined
behavior giving unexpected results with reasonable code.  There is
no reversal of unreversable instructions.

I am convinced that there is good reason to make the original code
be undefined behavior.  I never doubted that it was, just wanted an
example to help explain why.

John


[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]




