This subsumes Krzysztof's D48102, which itself was an alternative to D48032.
It does not include Krzysztof's 'Fix the "cannot join subranges" issue
caused by redefining an undef value' part of D48102, on the basis that
there is a different fix for that on D35073 that we need to refine and
upstream.
Change-Id: I73363db649916046eff58854c957d41a06157b3b
I have fixed this differently in the previous review.