label/jump optimization is influenced by the optimize.label[1..4] flags . --nolabelopt resets the label4 optimize flag. This disables the removal of non-reachable code. However, later on (in SDCCBBlock:iCodeFromeBBlock) this is flagged as an error or warning. In the case as reported in bug 3085434, the iffalse path is touched by jump-to-jump optimization, leaving the block with the original jump as dead-code, hence the waning. IMO --nolabelopt should not influence the removal of the unreached blocks but should not do the jump-to-jump optimization. This jum-to-jump optimization is switched on/off using the label3 optimzation flag. The same holds IMO for IFX label optimization ( influenced by the label2 optimize flag). Removal of non-reachable blocks should always be done, as it is a consequence of the other optimizations.
suppress unreachable-code warning solution
As the proposed fix changes --nolabelopt functionality and this might be unwanted another solution is to allow the check for dead-code only in case the label4 optimize flag is set. However, this suppresses all unreachable code warnings, also in case it is introduced by the user's own code.
Example:
int i = 10;
int main(void)
{
while (1)
{
if (--i == 0)
return(0);
}
return (1);
}
produces no unreachable-code warning.
Attachment -2 contains the patch to remove the warning for this case
Applied in reversion #9262.