From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1164f8,cf4ba3d07912d446 X-Google-Attributes: gid1164f8,public X-Google-Thread: 1094ba,cf4ba3d07912d446 X-Google-Attributes: gid1094ba,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: 359847639 Sender: keith@metropolis References: <01bd9013$76f09aa0$6f242499@stupidwin95> <35774C1A.2985A59E@rhea.umd.edu> <01bd9036$7ae7fea0$LocalHost@stupidwin95> <3577C554.9F50B096@nonexistant.com> <3pq$jBA3B$d1QAJU@POLYHDRN.demon.co.uk> 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 John Appleyard writes: > I totally agree about the dangers of uninitialised variables, array > bound errors and the like, and particularly about the incorrectness of > assuming that if it works with compiler A, but not with compiler B, then > compiler B is bugged - but... > ... this one looks like a compiler bug to me. I have to say I am beginning to come to that conclusion myself. I have just verified that the code works and gives the expected results for SGI and SunPRO compilers using either stack or static allocation. The DEC compiler with stack allocation is the only anomaly. > I'd be happier if I knew > the value if POSTMP(1) and POSION before the assignment to NGRPX, The values in posion were the same on entry to this routine and exit and have the values I gave. But *whatever* values it has, POSTMP should always be between 0.0 and 1.0 since it is assigned the value MOD(x, 1.d0). > I suppose NGRPX/Y/Z might be aliased, No, they are local scalar variables and not in common. So is POSTMP. > or the optimiser might have reordered code so that something > with an aliasing implication was executed after the 1101 loop and before > you inspected POSTMP, but that's a long shot. Well the value recorded by the debugger for POSTMP(1) is rather obviously the intermediate result of the computation of the 1st argument of the MOD function for IM=3, the last iteration of the 1101 loop. One might expect this to be held in a register and the array POSTMP optimizad away, but this value is clearly the one used in computing NGRPX. > I have found bugs just like this, even down to the WRITE making it go > away. The act of printing forces the optimiser to regularise things, It would presumably force a write to memory for the IO library calls and a subsequent reload. This would almost certainly fix any misallocation. > What does the compiler vendor say? Nothing yet as I haven't got an example anywhere near small enough to usefully report. I think I will though. The faulty value is produced within a very short region of flow control where I can see no stack/vs static errors, where no external subroutine is called which could conceivably screw things up. The only other way a bug elsewhere could affect this would be if it had clobbered a constant which was picked up and used. But this should affect POSTMP(1) and (2) as well. Combined with the fact that stack allocation with optimization works on Sun and SGI machines/compilers is useful (though not conclusive) evidence that it's not a simple program bug. Thanks for taking the trouble to study the details before posting! 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| ------------------------------------------------------------------------------