Safety-Critical Software – Optimizing Compilers

cembedded-systemsstandards

I'm reading some internal documentation for code developed to the MISRA C guidelines, and I see that in compiler flags section of the documentation there is a note to compile with optimisation off (-O0). I'm new to safety-critical development, so in my mind turning off optimisation is overly-pessimistic and modern compilers will produce valid code with moderate optimisation, and anyway a decent test suite will catch compiler flaws.

Are there good arguments for disabling optimisation? Perhaps because of this disabling, the code is riddled with left- and right-shifts replacing divisions and other micro-optimisations that I believe we should leave to the compiler to deal with.

Best Answer

I agree with you that it's overly pessimistic, but some (potentially historical) reasons:

  • DO-178C Level A code requires Source Code to Object Code Traceability, which is much harder to prove manually with optimized code (and qualified compilers are very expensive)
  • optimised code is harder to debug, which might prohibit scripted debugging opportunities
  • there could be more compiler bugs during optimization
Related Topic