<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/118246>118246</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[Clang]Uninitialized variables are set to -1 at optimization levels of - O1 and above
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
muxiff
</td>
</tr>
</table>
<pre>
Consider the following case ,
https://godbolt.org/z/8fKaq9Yhh
When the optimization level is - O1 or above, it is found that uninitialized variables are set to -1 by default, which is different from the behavior of gcc's policy setting to 0 by default. Is this the default policy of LLVM with optimization, is there a way to avoid it, or is it necessary to strictly manually set the initial value of all variables?
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyMkkGPm0gQhX9NcynZgjZgc-Dg8SzSame1p02UYwHVdEUN7XQXOJ5fH8E4miTKISekVr1HvVcfxsjDRFSr4kkVzwnOYn2ox_krG5O0vr_XFz9F7imAWALjnfM3ngboMBKovxr1dFGni0rPVuQa1eGsdKN0M_i-9U72PgxKN69KNyfzD36pPlmr0rNKz_DR0rR5-qvwyK8o7CdwtJADjrCD_zLwAbD1Cyl9AZb12fh56kEsCswTTyyMjl-phwUDY-soAgaCSALiYZdBe4eeDM5OVpOb5c6uPj0bQ4EmARP8uO3RksWFfQBvYOg6pY8Rrt5xd1_tZA0tHtIfHPfwdwSxHDf94_G7xht4efnwL9xY7E8ZtzCbJBAg3PC--uLiuQfetvRhHWCBiTqKEcM2ESVwJ-4OI04zOnd_S2kJHj3Agm6m9cfo3HshjyNVzVvxSV8f-upQYUJ1djwcsiytyjKxddoWhaH81PbHU5YXORZZRV1bGdNRoQ9lwrVOdZ7pVKeHXOflvjiVXZa35YnSrKyyo8pTGpHd3rllXE-fcIwz1Vl20nmZOGzJxQ01rTuH06C0XqkL9SrYtfMQVZ46jhLfLYTFbXxeNkXx_P8f3R3lN2DFtZyNLJz6N7SSObj6F3ZZ7NzuOz8q3ax7PD67a_CfqROlmy1XVLp5RFtq_S0AAP__fEkZQA">