https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105453

            Bug ID: 105453
           Summary: wrong choice of source in load instruction
           Product: gcc
           Version: 11.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: absoler at smail dot nju.edu.cn
  Target Milestone: ---

Created attachment 52917
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=52917&action=edit
concurrent case

Here's the code:

int g_6[2] = {0x67D50F82L,0x67D50F82L};
int g_10 = 0L;

int func_1(void)
{ 
    int *l_9 = &g_10;
    (*l_9) = (g_6[0]);
    if (g_6[1])
    {
        return g_10;
    }
    return 1;
}

and on gcc-11.3.0 with -O1 option, the assembly code are as follows:

   0x000000000040114d <+0>:     mov    0x2eed(%rip),%eax        # 0x404040
<g_6>
   0x0000000000401153 <+6>:     mov    %eax,0x2ef3(%rip)        # 0x40404c
<g_10>
   0x0000000000401159 <+12>:    cmpl   $0x0,0x2ee4(%rip)        # 0x404044
<g_6+4>
   0x0000000000401160 <+19>:    mov    $0x1,%eax
   0x0000000000401165 <+24>:    cmovne 0x2ed4(%rip),%eax        # 0x404040
<g_6>
   0x000000000040116c <+31>:    retq

yes, it assert that g_10 = g_6[0] and this may cause problem in concurrent
environment. The case files uploaded can show that the generated code is the
same as above in an environment that g_6 may be modified by other thread.

Reply via email to