<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/109886>109886</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
false negative unsigned integer overflow when using optional branches
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
carenas
</td>
</tr>
</table>
<pre>
The following code:
```c
int main(void)
{
unsigned i = 1;
int c = 1;
if (c) {
while (i-- > 0) { }
} else {
return i;
}
return 128;
}
```
shows
```
$ clang -fsanitize=integer t.c
$ ./a.out; echo $?
t.c:9:11: runtime error: unsigned integer overflow: 0 - 1 cannot be represented in type 'unsigned int'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior t.c:9:11
128
```
note that while the variable is being used in the `else` branch, the execution through the main branch where it wraparounds, prevents it to reaching that path, and therefore even if technically DID wraparound, reporting that is nit useful.
Additionally, it doesn't trigger if the variable is `signed` (which is actually UB), so there might be a fix in that implementation which might be missing for unsigneds.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJx0VE2vozYU_TXO5irIGB6EBYtk0khdzKbTWXRpzAXfytjINsm8_vrKwHuJplMpCsLn3HPP_cAyBBotYsveLuztepBL1M63Snq0Mhw617-3f2qEwRnjHmRHUK5HVpwZvzL-8V_x7ae2d7IRJkmWidPdUc9Es_Pqy0dYs9g1cQ8ErLhCzoonluLVf44_wAGYOCkmGnjVY7x5aDKYQDoegRW_Ad9JwOrrk1hfAU3An6M9xsVboFcjr3E7novTk_EJfzRgew3aPcIvESZKUEbaEY5DkJYi_YOsuJKNOKKHmKknL2PiJjO3RFZcAJV2wETJitvGSNTi3LDinOesOINfbKQJAb13Ph08G7yLuzv6wbhHAjkcIQclrXUROgSPs8eANq58iO9zamT9qsFEvWX-9v3r1_MffyWZ77bHgSz2F9TyTs5_22vaHezosdtheHUNm1xq6K9aZV1EiFpG2OYaNcJdepKdQaAAHaZtXMLuWCOwiqfBsopD56VVmokvK4A_UC2RXKJ5t4x6PU0buhPhodEjUISHl7P0brF9SNGzxzvaGBIUHXiUSqe0q69ZxjWFtH0S9Dg4j5ACgAaIqLQlJY15h-vv1xflFONxdj5-SlEASzFVMywme934c99Tsp50UiBF6B0Gy0QdIXoa02hTup_awyq-zS61g4nTQ5PSCZAqLqup75f0YYovENxmHyYa9boOEgb6sbU1mZtmgxPaKNcebkqf3IlCSHUMzn_uXMgOfVv0TdHIA7Z5LWohiorzg26bvukUz8u66irEvFJllVd9J_pSvHVdUx-oFVyUvBFvnAvOeVbIUjRSochPfVPmOSs5TpJMZsx9ypwfDxTCgm3Om9OpOhjZoQnrfSaExQesKBMiXW--TUHHbhkDK7mhEMNTJlI02A4yXQ4WRxnpjv__GaWdsbCstbt5G9G-ThgOizetjnEO6aoUNyZuI0W9dJlyExO3lHN_HGfv_kYVmbitTgMTt72Ueyv-DQAA__8_q77p">