Add a work-around for #7978.

This patch fixes profiling at the cost of losing cost centre accounting in a
very small number of cases. I am working on a better fix.