<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/86498>86498</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Incorrect transformation for loops by optimization passes
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
ararmine
</td>
</tr>
</table>
<pre>
When compiling the following example with clang -O3 opt level, the program does not print the expected output and the returned status is 48.
Steps to reproduce:
```
1. cat bug.cpp
#include <stdio.h>
#include <stdlib.h>
struct C {
int i[100000000];
};
int main()
{
// Eat all available chunks of memory that are big enough for
// struct C so that the next allocation request will fail.
while (malloc(sizeof(struct C)));
printf("End\n");
return 0;
}
```
```
2. clang++ bug.cpp -O3
3. ./a.out
4. echo $?
48
```
This is the generated LLVM IR after the optimizations. The loop is optimized away and so is 'printf':
```
define dso_local noundef i32 @main() local_unnamed_addr #0 !dbg !267 {
unreachable, !dbg !268
}
```
Compiling the same example with GCC, the program produces the following output:
```
1. g++ bug.cpp -O3
2. ./a.out
End
3. echo $?
0
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyMVF2PqzYQ_TXmZbQIDAnkgYeb7Ka60q0qtVft48rYA7g1NvXHZvf--som6SarbFWE-JgzHo_nnBnmnBw1Ykc2e7J5zFjwk7Eds8zOUmPWG_HW_TGhBm7mRSqpR_ATwmCUMqf4h69sXhTCSfoJuGJ6hIdfKjCLB4UvqAg9pBWLNaNlMwiDDrTxsFipfYLwdUHuUYAJfgkemBbJbtEHq1GA88wHB9JB3eakeCTFl988Lg68AYuLNSJwJNWXFSLb4nyn3zIHzjz0Ycz5spxdaCU1V0EgkOrgvJAmn0j19AmqZH8Np6fzNnAPByDNfrVAPI8km31ZnC-yeSTVGSXN1Xd6RveZSU1oS-ju4nUJBoQeCT3CE_PAlAL2wqRivULgU9B_OTADzDgb-wZ-ij4WoZcjoDZhn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