<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/75997>75997</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Increasing the Hamming distance for defense programming may be optimized by the compiler.
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          zhou-shan
      </td>
    </tr>
</table>

<pre>
    1. The code that caused the error is as follows:(test.c)
`enum {
TEST_XXX_ENABLED = 0x5AA55AA5;
TEST_XXX_DISABLED = 0xA55AA55A;
};
static uint32_t g_test_xxx_flag = TEST_XXX_DISABLED;

attribute ((noline)) bool test_xxx_is_enable(void)
{
return g_test_xxx_flag == TEST_XXX_ENABLED;
}

attribute ((noline)) bool test_xxx_enable(void)
{
g_test_xxx_flag = TEST_XXX_ENABLED;
}`
2. The optimization level is Os.
3. Problem Description:
![image](https://github.com/llvm/llvm-project/assets/16482877/ee7926cc-9b8e-449a-be4c-7d0e24566edd)
The function works normally, but the secure programming design (increasing the Hamming distance) is optimized by the compiler. In the final generated executable program:
- The size of g_test_xxx_flag is reduced from 4 bytes to 1 byte.
- The operations of assigning and comparing g_test_xxx_flag are both replaced with 0/1.
We expect to generate the following assembly instruction sequence:
![image](https://github.com/llvm/llvm-project/assets/16482877/e18692ad-e93a-4019-9c3c-14b22b29bb7a)

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy0VM1u6zYTfRp6M5BAUf8LLZzPMb4ARVvgBmh2BkmNJLYU6ZJUYufpC0r5ubn3IkULdGGbpg7OnDNzNNx7NRrEjpQ3pDzs-BIm67rnyS6Jn7jZCdtfuyyF-wlB2h4hTDyA5IvHHsKEgM5ZB8oD9zBYre2TJ_mesCagD6kkrCX0QOieVBTNMgOpb7aL-9sv96eHh4fT7c_7m59uD0DyA9BLud-X8UPyb3GHuy9fAzd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