Wrong heuristic on unreachable code detection

Hi,

I'm currently developping a project where some code was marked as "unreachable" by AppCode, although it's clearly not the case. I tried to extract a small (meaningless) pattern that reproduce the problem:

int x = 0;
do {
    if (rand() & 1) x++;
    if (x < 10) continue;
    return YES;
} while(rand() < 100);



Yes, I know that I could actually write things in a more conventional way, but this is not the point ;)

In this example, the code following the closing bracket (the "while" statement and all the code after the while) is considered as unreachable. I think this is related to the basic block ending with a "return" statement, but, if you look closely, there is a "continue" statement before that is triggered sometimes (depends on the number of odd numbers that will be returned by the rand() function), and the code after the while may be executed if a rand number greater than 100 is produced at this point. In all the cases, the code will always ends.

I hope that this code snippet will help you find the problem.
7 comments

Nice finding. It's best to report any bugs directly to the tracker: http://youtrack.jetbrains.net/issues/OC

I've taken the liberty to experiment a little with your code, simplified it even more and posted the result here:
http://youtrack.jetbrains.net/issue/OC-2249

0

Yes, this is a bug. AppCode analyzer treats "continue" as a jump to the beginning of the loop rather than to the condition. This is wrong for do-while loop.
Thank you, we'll fix it ASAP.

0

sorry, I hadn't thought about looking for a bugtracker ...

Thank you for having filled the bug for me!

0

half an hour ..marked as fixed. Impressive! That's why I enjoy reporting bugs to Jetbrains ;-).

0

woah!

I just bought the final 1.0 version, and it seems that the fix has already been commited to this version!

Great :)

0

No, it's still not. However, it will be available soon in a bugfix release (in a couple of weeks).

0

Please sign in to leave a comment.