* Re: Alpha compiler bug
[not found] <3houb5$8cr@vixen.cso.uiuc.edu>
@ 1995-02-14 8:01 ` David Gelhar
1995-02-15 9:57 ` Ronald F. Guilmette
1995-02-14 14:21 ` Stefan Monnier
` (2 subsequent siblings)
3 siblings, 1 reply; 10+ messages in thread
From: David Gelhar @ 1995-02-14 8:01 UTC (permalink / raw)
In article <3houb5$8cr@vixen.cso.uiuc.edu>, peltz@cerl.uiuc.edu (Steve
Peltz) wrote:
> DEC OSF/1 V3.0 (Rev. 347)
>
> Expression such as:
> (temp = a + b, temp * (a + b)) + (temp = c + d, temp * (c + d))
>
> do not compile correctly with optimization level greater than 0. It uses
> the same value of temp for both multiplies, instead of correctly handling
> the parenthesized comma separated expressions.
>
> E.g. a=1, b=2, c=3, d=4, the correct answer is 58; the incorrect answer
> given with -O1 is 70.
>
> Am I confused and this is actually undefined behavior for ANSI, or is this
> a compiler bug? Is there a patch?
Looks like undefined behavior to me.
Within the subexpressions there is a sequence point (comma), so we know
"temp = a + b" is evaluated before "temp * (a + b)" (and so forth).
As far as I can tell, though, there's no sequence point between
"temp = a + b" and "temp = c + d", so we don't know anything about the
order of evaluation of the two assignments. Assigning to the same variable
twice without an intervening sequence point means the results are undefined.
The comp.std.c lawyers may be able to give a more definitive chapter & verse
answer (Note the crossposting!)
--
David Gelhar david.gelhar@dartmouth.edu
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Alpha compiler bug
[not found] <3houb5$8cr@vixen.cso.uiuc.edu>
1995-02-14 8:01 ` Alpha compiler bug David Gelhar
@ 1995-02-14 14:21 ` Stefan Monnier
1995-02-14 17:15 ` Peter da Silva
1995-02-14 19:45 ` Dave Hill
3 siblings, 0 replies; 10+ messages in thread
From: Stefan Monnier @ 1995-02-14 14:21 UTC (permalink / raw)
In article <3houb5$8cr@vixen.cso.uiuc.edu>,
Steve Peltz <peltz@cerl.uiuc.edu> wrote:
] Expression such as:
] (temp = a + b, temp * (a + b)) + (temp = c + d, temp * (c + d))
]
] do not compile correctly with optimization level greater than 0. It uses
] the same value of temp for both multiplies, instead of correctly handling
] the parenthesized comma separated expressions.
]
] E.g. a=1, b=2, c=3, d=4, the correct answer is 58; the incorrect answer
] given with -O1 is 70.
]
] Am I confused and this is actually undefined behavior for ANSI, or is this
] a compiler bug? Is there a patch?
As far as I know, ANSI C doesn't specify any evaluation order in
expression. Of course, the comma operator specifies a sequential
order. But basically, the constraints are:
temp = a + b before temp * (a + b)
temp = c + d before temp * (c + d))
but that's all. So, it seems totally correct to rewrite the thing
into:
(temp = a + b, /* junked cause useless */
temp = c + d,
(temp * (a + b)) + (temp * (c + d)))
Stefan
--
--------------------------------------------------------------------
-- Suicidez-vous jeune, vous profiterez plus longtemps de la mort --
--------------------------------------------------------------------
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Alpha compiler bug
[not found] <3houb5$8cr@vixen.cso.uiuc.edu>
1995-02-14 8:01 ` Alpha compiler bug David Gelhar
1995-02-14 14:21 ` Stefan Monnier
@ 1995-02-14 17:15 ` Peter da Silva
1995-02-14 19:08 ` Steve Peltz
1995-02-14 19:45 ` Dave Hill
3 siblings, 1 reply; 10+ messages in thread
From: Peter da Silva @ 1995-02-14 17:15 UTC (permalink / raw)
In article <3houb5$8cr@vixen.cso.uiuc.edu>,
Steve Peltz <peltz@cerl.uiuc.edu> wrote:
> Expression such as:
> (temp = a + b, temp * (a + b)) + (temp = c + d, temp * (c + d))
> do not compile correctly with optimization level greater than 0. It uses
> the same value of temp for both multiplies, instead of correctly handling
> the parenthesized comma separated expressions.
This is actually undefined behaviour for ANSI. All the comma operators
guarantee is that "temp = a + b" will be evaluated before "temp * (a + b)",
and similarly for the second expression.
It is legal for the compiler to evaluate this as:
temp = a + b;
temp = c + d;
... temp * (a + b) + temp * (c + d);
--
Peter da Silva `-_-'
Network Management Technology Incorporated 'U`
1601 Industrial Blvd. Sugar Land, TX 77478 USA
+1 713 274 5180 "Hast du Heute schon deinen Wolf umarmt?"
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Alpha compiler bug
1995-02-14 17:15 ` Peter da Silva
@ 1995-02-14 19:08 ` Steve Peltz
1995-02-16 17:50 ` Peter da Silva
0 siblings, 1 reply; 10+ messages in thread
From: Steve Peltz @ 1995-02-14 19:08 UTC (permalink / raw)
In article <id.M3CH1.QJF@nmti.com>, Peter da Silva <peter@nmti.com> wrote:
>In article <3houb5$8cr@vixen.cso.uiuc.edu>,
>Steve Peltz <peltz@cerl.uiuc.edu> wrote:
>> Expression such as:
>> (temp = a + b, temp * (a + b)) + (temp = c + d, temp * (c + d))
>
>This is actually undefined behaviour for ANSI. All the comma operators
>guarantee is that "temp = a + b" will be evaluated before "temp * (a + b)",
>and similarly for the second expression.
Is this true for an argument list as well? My actual problem occurred
when I tried to pass the two subexpressions to a function, rather than
add them together.
Is there any way to force the order for something like this? This is actually
a macro expansion, where in the general case it needs to look like a single
expression (it might be a macro expansion, or it might be a function call).
--
Steve Peltz
tricorn@uiuc.edu
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Alpha compiler bug
[not found] <3houb5$8cr@vixen.cso.uiuc.edu>
` (2 preceding siblings ...)
1995-02-14 17:15 ` Peter da Silva
@ 1995-02-14 19:45 ` Dave Hill
1995-02-21 17:37 ` HP LJ4M on OSF/3 Tadhg McCarthy
1995-02-21 17:41 ` PCL files on a HP4M printer Tadhg McCarthy
3 siblings, 2 replies; 10+ messages in thread
From: Dave Hill @ 1995-02-14 19:45 UTC (permalink / raw)
To: Steve Peltz
In article <3houb5$8cr@vixen.cso.uiuc.edu>, peltz@cerl.uiuc.edu (Steve Peltz) writes:
|> DEC OSF/1 V3.0 (Rev. 347)
|>
|> Expression such as:
|> (temp = a + b, temp * (a + b)) + (temp = c + d, temp * (c + d))
|>
|> do not compile correctly with optimization level greater than 0. It uses
|> the same value of temp for both multiplies, instead of correctly handling
|> the parenthesized comma separated expressions.
|>
|> E.g. a=1, b=2, c=3, d=4, the correct answer is 58; the incorrect answer
|> given with -O1 is 70.
|>
|> Am I confused and this is actually undefined behavior for ANSI, or is this
|> a compiler bug? Is there a patch?
|> --
|> Steve Peltz
|> tricorn@uiuc.edu
The same behavior is seen with v3.2 so I doubt there is a patch yet.
You may wish to use the -migrate option which invokes the decc compiler.
This compiler produces the value that you expected. (You may have to
install the optional subset that contains decc. OSFDECC300 ???
You should also report this to Digital Customer Support.
/Dave
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Alpha compiler bug
1995-02-14 8:01 ` Alpha compiler bug David Gelhar
@ 1995-02-15 9:57 ` Ronald F. Guilmette
0 siblings, 0 replies; 10+ messages in thread
From: Ronald F. Guilmette @ 1995-02-15 9:57 UTC (permalink / raw)
In article <David.Gelhar-1402950301440001@lemitar.dartmouth.edu>,
David Gelhar <David.Gelhar@Dartmouth.EDU> wrote:
>In article <3houb5$8cr@vixen.cso.uiuc.edu>, peltz@cerl.uiuc.edu (Steve
>Peltz) wrote:
>
>> DEC OSF/1 V3.0 (Rev. 347)
>>
>> Expression such as:
>> (temp = a + b, temp * (a + b)) + (temp = c + d, temp * (c + d))
>>
>> do not compile correctly with optimization level greater than 0. It uses
>> the same value of temp for both multiplies, instead of correctly handling
>> the parenthesized comma separated expressions.
>>
>> E.g. a=1, b=2, c=3, d=4, the correct answer is 58; the incorrect answer
>> given with -O1 is 70.
>>
>> Am I confused and this is actually undefined behavior for ANSI, or is this
>> a compiler bug? Is there a patch?
>
>
>Looks like undefined behavior to me.
Yep. And this was confirmed by X3J11/WG14 in their response to Defect
Report number 117 (which, not coincidently, asked about a very very similar
expression).
>Within the subexpressions there is a sequence point (comma), so we know
>"temp = a + b" is evaluated before "temp * (a + b)" (and so forth).
>
>As far as I can tell, though, there's no sequence point between
>"temp = a + b" and "temp = c + d", so we don't know anything about the
>order of evaluation of the two assignments. Assigning to the same variable
>twice without an intervening sequence point means the results are undefined.
I've always been mildly troubled about the loose way that the committee
used the word ``between'' when speaking of sequence points. In the vast
majority of cases in the standard, the word ``between'' means ``textually
between'', whereas in the case of sequence points, any use of the word
``between'' really means ``between, in time''. This important point got
lost someplace during the drafting of the standard.
>The comp.std.c lawyers may be able to give a more definitive chapter & verse
>answer (Note the crossposting!)
Consider it done. (I happen to have been the one who filed DR #117, and I
was present and accounted for when the response was drafted and approved,
so I guess that I can count myself as among the ``language lawyers'' of
record with regard to this question.)
--
-- Ron Guilmette, Sunnyvale, CA ---------- RG Consulting -------------------
---- E-mail: rfg@segfault.us.com ----------- Purveyors of Compiler Test ----
-------------------------------------------- Suites and Bullet-Proof Shoes -
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Alpha compiler bug
1995-02-14 19:08 ` Steve Peltz
@ 1995-02-16 17:50 ` Peter da Silva
1995-02-18 17:53 ` Dan Pop
0 siblings, 1 reply; 10+ messages in thread
From: Peter da Silva @ 1995-02-16 17:50 UTC (permalink / raw)
In article <3hqv3e$qb2@vixen.cso.uiuc.edu>,
Steve Peltz <peltz@cerl.uiuc.edu> wrote:
> In article <id.M3CH1.QJF@nmti.com>, Peter da Silva <peter@nmti.com> wrote:
> >This is actually undefined behaviour for ANSI. All the comma operators
> >guarantee is that "temp = a + b" will be evaluated before "temp * (a + b)",
> >and similarly for the second expression.
> Is this true for an argument list as well?
The commas in argument lists are not comma operators and do not generate
a sequence point. For example:
i = 1;
printf("%d, %d", i++, i++);
Might generate:
1, 2
2, 1
1, 1
(since this is "undefined behaviour" it might also send dirty pictures to
clinton@whitehouse.gov)
> Is there any way to force the order for something like this?
Generate multiple temporaries.
> This is actually
> a macro expansion, where in the general case it needs to look like a single
> expression (it might be a macro expansion, or it might be a function call).
It is considered bad form to pass an expression with a side effect to a macro.
You may not be able to use macros in this case.
--
Peter da Silva `-_-'
Network Management Technology Incorporated 'U`
1601 Industrial Blvd. Sugar Land, TX 77478 USA
+1 713 274 5180 "Hast du Heute schon deinen Wolf umarmt?"
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Alpha compiler bug
1995-02-16 17:50 ` Peter da Silva
@ 1995-02-18 17:53 ` Dan Pop
0 siblings, 0 replies; 10+ messages in thread
From: Dan Pop @ 1995-02-18 17:53 UTC (permalink / raw)
In <id.D8EH1.K7K@nmti.com> peter@nmti.com (Peter da Silva) writes:
>In article <3hqv3e$qb2@vixen.cso.uiuc.edu>,
>Steve Peltz <peltz@cerl.uiuc.edu> wrote:
>
>> This is actually
>> a macro expansion, where in the general case it needs to look like a single
>> expression (it might be a macro expansion, or it might be a function call).
>
>It is considered bad form to pass an expression with a side effect to a macro.
It's considered even worse form to write macros that evaluate their
arguments more than once. ANSI/ISO C requires that any macro defined
in a standard header (an implementation is allowed to provide macro
replacements for any standard function, provided that the function is
available in the standard library, too) evaluates its arguments only once.
Two exceptions: getc and putc (only the second argument of putc may be
evaluated more than once)
Dan
--
Dan Pop
CERN, CN Division
Email: danpop@cernapo.cern.ch
Mail: CERN - PPE, Bat. 31 R-004, CH-1211 Geneve 23, Switzerland
^ permalink raw reply [flat|nested] 10+ messages in thread
* HP LJ4M on OSF/3
1995-02-14 19:45 ` Dave Hill
@ 1995-02-21 17:37 ` Tadhg McCarthy
1995-02-21 17:41 ` PCL files on a HP4M printer Tadhg McCarthy
1 sibling, 0 replies; 10+ messages in thread
From: Tadhg McCarthy @ 1995-02-21 17:37 UTC (permalink / raw)
PCL files not printing out properly on HP4M. I am getting
header page which includes some of the PCL commands.
I am using the printer filter "hplaserof".
Anyone got any suggestions ?
^ permalink raw reply [flat|nested] 10+ messages in thread
* PCL files on a HP4M printer.
1995-02-14 19:45 ` Dave Hill
1995-02-21 17:37 ` HP LJ4M on OSF/3 Tadhg McCarthy
@ 1995-02-21 17:41 ` Tadhg McCarthy
1 sibling, 0 replies; 10+ messages in thread
From: Tadhg McCarthy @ 1995-02-21 17:41 UTC (permalink / raw)
Tadhg.
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~1995-02-21 17:41 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <3houb5$8cr@vixen.cso.uiuc.edu>
1995-02-14 8:01 ` Alpha compiler bug David Gelhar
1995-02-15 9:57 ` Ronald F. Guilmette
1995-02-14 14:21 ` Stefan Monnier
1995-02-14 17:15 ` Peter da Silva
1995-02-14 19:08 ` Steve Peltz
1995-02-16 17:50 ` Peter da Silva
1995-02-18 17:53 ` Dan Pop
1995-02-14 19:45 ` Dave Hill
1995-02-21 17:37 ` HP LJ4M on OSF/3 Tadhg McCarthy
1995-02-21 17:41 ` PCL files on a HP4M printer Tadhg McCarthy
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox