Usenet comp.sys.dec (1990-2013)
 help / color / mirror / Atom feed
From: Paul Winalski <winalski@lspace.zko.dec.com>
To: "Kevin G. Rhoads" <T_Rhoads@NoSpam.CLASSIC.MSN.COM>
Subject: Re: Mysterious data corruption in Fortran with -automatic
Date: 1998/06/08	[thread overview]
Message-ID: <357C38B6.B9546F8@lspace.zko.dec.com> (raw)
In-Reply-To: 01bd9036$7ae7fea0$LocalHost@stupidwin95


Kevin G. Rhoads wrote:
> 
> Please read what I wrote and respond to that.
> 
> If the code gives CORRECT answers with compiler
> optimizations OFF and it gives WRONG answers
> with compiler optimizations ON -- question, where
> is the bug?
> 
> Answer, in the compiler optimizations -- the code
> did NOT change, the compiler did.

When a program works with optimization turned off
but not when optimization is turned on, it usually
means one of two things:

1) The program is an illegal program that is doing
   something that the language definition says is
   illegal or has undefined or unpredictible results.

2) The program is triggering a compiler bug.

It's been my experience that the majority of
"optimizer bugs" turn out to be illegal programs.
It's quite easy to introduce these sorts of problems
into your code.  Just one small Fortran example:

    IF (A .NE. B) .AND. (FUNC(X, Y) .NE. 4)

where FUNC is a function that, as a side effect,
modifies variable Y, followed later by some code
that depends on FUNC having changed Y's value as
a result of the execution of the IF statement.
The Fortran language does not guarantee the order
of evaluation of expressions of equal precedence;
the compiler is free to evaluate the comparison of
A and B first and then shortcut the expression if
they're equal, so that FUNC never gets called.

When optimization is turned off, a simple-minded
full evaluation of the expression might take place,
so that the code seems to "work", but it "breaks"
if you turn on optimization and the compiler decides
to exercise its right not to call FUNC if it can
evaluate the expression without doing so.

This is a case where the code didn't change, but it
is not an optimizer bug.  The program is depending
on a particular result from an operation that is
defined in the language as being unpredictible.

--PSW



  parent reply	other threads:[~1998-06-08  4:00 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-06-04  4:00 Mysterious data corruption in Fortran with -automatic Keith Refson - real email address in signature
1998-06-04  4:00 ` Thorsten Ohl
1998-06-04  4:00 ` Kevin G. Rhoads
1998-06-04  4:00   ` Jeffrey J. Potoff
1998-06-04  4:00     ` Kevin G. Rhoads
1998-06-05  4:00       ` Jeffrey J. Potoff
1998-06-05  4:00       ` Keith Refson - real email address in signature
1998-06-05  4:00         ` Kevin G. Rhoads
1998-06-05  4:00         ` Robert O'Dowd
1998-06-05  4:00           ` John Appleyard
1998-06-05  4:00             ` Keith Refson - real email address in signature
1998-06-05  4:00           ` Kevin G. Rhoads
1998-06-05  4:00       ` Robert O'Dowd
1998-06-05  4:00         ` Kevin G. Rhoads
1998-06-05  4:00           ` Jeffrey J. Potoff
1998-06-05  4:00           ` Stuart Brook
1998-06-05  4:00       ` Harald Anlauf
1998-06-05  4:00         ` Kevin G. Rhoads
1998-06-08  4:00       ` Paul Winalski [this message]
1998-06-04  4:00     ` Stuart Brook
1998-06-04  4:00       ` Kevin G. Rhoads
1998-06-05  4:00         ` Stuart Brook
1998-06-05  4:00       ` Toon Moene
1998-06-04  4:00     ` Kevin G. Rhoads
1998-06-05  4:00       ` Ian Pattie
1998-06-05  4:00         ` Jeffrey J. Potoff
1998-06-05  4:00           ` Kevin G. Rhoads
1998-06-06  4:00           ` Rob Komar
1998-06-05  4:00       ` Ian Chivers
1998-06-05  4:00         ` Kevin G. Rhoads
1998-06-05  4:00       ` William Clodius
1998-06-05  4:00       ` Thorsten Ohl
1998-06-05  4:00         ` Kevin G. Rhoads
1998-06-05  4:00           ` William Clodius
1998-06-04  4:00     ` Kevin G. Rhoads
1998-06-05  4:00       ` Catherine Rees Lay
1998-06-06  4:00 ` SUMMARY: Code errors which can masquerade as compiler bugs " Kevin G. Rhoads
1998-06-11  4:00   ` Ron Sverdlove x2517
1998-06-08  4:00 ` Steve Lionel
read-only archive

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox