<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/54169>54169</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Incorrect behaviour with O2 compile when integer overflow
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
xuechiyaobai
</td>
</tr>
</table>
<pre>
I complie C++ program with below code:
"""
#include <iostream>
volatile int b = 0x7fffffff;
volatile int d = 0x0;
int main(int argc, const char * argv[]) {
void* a = malloc(0x10);
*(int*)a = d;
int c = std::max(*(int*)a, b + 1);
printf("%d\n", c);
return 0;
}
"""
If I complie with -O0, the output is "0"
when I compile with -O2, the output is "-2147483648", and I think it is incorrect behaviour
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJxtU8uyoyAQ_RrcUEkhaNSFizxmqrK634CCyh2UFKDJ_ftp0ElmMpeiEOhzug_dbWPEV33FrRlvWkl8RvQEE9-s6S0f8V35ATdSmztAhETsiMgFkSOidJvbkamp1bOQGLGzMs5byUfEfmzmuC5Gc6-0xGryuAHgBZNH0a0DsdM3KLGhyNO8rsE2cjUhWoYtt32L6BkkTs7jduAWI3oM1wvKTyi_IFphVGwuMIzFKBEhMcDItTbgoSSPlAD2GS1AAbaGiZtqZYh_IEFDG--dFyFH7DjyB7DeuUEkvBwSnL6HuVmAdZEDec0Fys9T3MKz3rFW-tlO-K-sFJfv6xLXa4dfFY4V3X2Q4NgPEpvZ32aPlQNZlDyZ90FOGysUY2PRb1k7mmZFVrJDVm6K-SSA7Ac1_cIqwqA9jLWyhcrLgS_KzDYRNRMVq3jildeyvv4PWeN-0JeOIAsSJXtpsVmk7aA1k9nqevD-5kLu6U-YPfDmZg80OGi9_PnsoLE_IQQclXOzdLDJs_RQJUNddJznGW_T5iDKppE0P5AuYzSTeVXQnCWaw5_g6tBSlE7yjqOL8OT8kqiaEkggIywlacryfXNIZVVUecWoKFMoaEYk9KzeBx17Y_vE1lFSM_cOjFo5715G7pzqJynrtYMTPvvB2Poxy3ZQX9w0XCUxfh31_wZhehsY">