From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1094ba,cf4ba3d07912d446 X-Google-Attributes: gid1094ba,public X-Google-Thread: 1164f8,cf4ba3d07912d446 X-Google-Attributes: gid1164f8,public From: rubber@bounce.com (Keith Refson - real email address in signature) Subject: Re: Mysterious data corruption in Fortran with -automatic Date: 1998/06/05 Message-ID: #1/1 X-Deja-AN: 359765672 Sender: keith@metropolis References: <01bd9013$76f09aa0$6f242499@stupidwin95> <35774C1A.2985A59E@rhea.umd.edu> <01bd9036$7ae7fea0$LocalHost@stupidwin95> Content-Type: text/plain; charset=US-ASCII Organization: Oxford University Mime-Version: 1.0 (generated by tm-edit 7.106) Newsgroups: comp.sys.dec,comp.lang.fortran "Kevin G. Rhoads" writes: > If the code gives CORRECT answers with compiler optimizations OFF > and it gives WRONG answers with compiler optimizations ON -- > question, where is the bug? I know this seems like an obvious conclusion but I am afraid in my (many years of) experience it is false. One obvious way this might happen is if you omitted to initialize a variable. Compiling with no optimization will often result in it being initialized to zero -- even though you didn't ask for it in your code. However the optimized code will pick up whatever value was last in some register or memory location and will therefore give different results. Another mistake is to pass the same actual argument twice to two different dummy arguments in a subroutine. The standard entitles the compiler to assume that these refer to distinct areas of store and optimizing on that assumption may not produce the results you intended. Yet another faulty but common assumption is that variables retain their values between invocations of a subprogram. > Answer, in the compiler optimizations -- the code did NOT change, > the compiler did. But incorrect code with "undefined" behaviour may yet produce "correct" results. Perhaps the language lawyers don't make this point sufficiently clear..... Nevertheless I believe the part of code that I am having trouble with and started this thread about does *not* suffer from failure to initialize, aliasing or assumptions of SAVE behaviour or array bounds errors (at least not in the part where the faulty result occurs). Does anyone have any further suggestions as to what to look for? If not then maybe this really is one of the relatively rare cases of a genuine optimizer bug. Keith refson -- ------------------------------------------------------------------------------ Email: Keith.Refson@ | Tel: +44 1865 272026 | Dr Keith Refson, | earth.ox.ac.uk | Fax: +44 1865 272072 | Dept of Earth Sciences | | Parks Road, Oxford OX1 3PR, UK| ------------------------------------------------------------------------------