Issue 75997
Summary Increasing the Hamming distance for defense programming may be optimized by the compiler.
Labels new issue
Assignees
Reporter zhou-shan
    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)

_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to