Compiler Bugs

| SimCon Home | fpt Reference Manual Home |

Are Compiler Bugs Common?

No. Our experience is that compilers are very well tested. Bugs tend to occur either in resource limitations or in very little used constructs. We have seen bugs in every major compiler we have used, but, except for resource problems, they have occurred in issues such as overloaded assignments, elemental functions using arrays of derived types and deliberatley misaligned EQUIVALENCE statements. All these usages are rare.

Detection of Compiler Bugs

It is possible to check for compiler bugs in the compilation of a specific program. The program is compiled with two different compilers and the results of runs are compared. Usually the results will be different because of numerical drift. Small differences in the results of expressions cumulate and the reults drift apart. Numerical drift is expected because the order of computation of at least some expression in Fortran is undefined. The numerical drift is removed as follows.

The program code is instrumented to capture a record of the program flow at run-time, and a trace of every left-hand-side quantity computed. The record is captured to file with the first compiler.

The program is then built with the second compiler and is run again. On this occasion the routines inserted into the code to capture the trace read the trace from the first run. If the flow differs, the run halts with a diagnostic. If the flow is the same, every value computed is compared with the value from the first run. If the value differs by more than a criterion amount a report is recorded. If the value differs at all the value computed in the second run is overwritten by the value in the first run. This prevents the drift.

The fpt command to instrument the code to capture the flow and data is:


This procedure, and some results of its use, is described in detail in Collins J, Farrimond B, Flower D, Anderson M and Gill D. 2013, "The Removal of Numerical Drift from Scientific Models", arXiv:1304.3260 [cs.SE].

Copyright ©1995 to 2023 Software Validation Ltd. All rights reserved.