<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Overly optimized simultaneous copy of struct fields corrupts destination struct"
   href="https://bugs.llvm.org/show_bug.cgi?id=50623">50623</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Overly optimized simultaneous copy of struct fields corrupts destination struct
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>12.0
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>LLVM Codegen
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>samuel.sadok@bluewin.ch
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org, neeilans@live.com, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Clang 12.0.0 modifies a field of a struct that should not be modified. This is
a regression from clang 11.0.1.

Input File:
```
struct S { char val1; char padding; short val2; };

void func(struct S src, struct S* dest) {
    dest->val1 = src.val1;
    dest->val2 = src.val2;
}
```

Output from clang 12.0.0 (clang -c test.c -o test.o -O1 && objdump -S test.o -M
intel):
```
0000000000000000 <func>:
   0:   89 3e                   mov    DWORD PTR [rsi],edi
   2:   c3                      ret    
```

Output from clang 11.0.1:
```
0000000000000000 <func>:
   0:   40 88 3e                mov    BYTE PTR [rsi],dil
   3:   c1 ef 10                shr    edi,0x10
   6:   66 89 7e 02             mov    WORD PTR [rsi+0x2],di
   a:   c3                      ret    
```

The output from clang 12.0.0 is incorrect because it modifies the field
`dest->padding`.

See also here: <a href="https://godbolt.org/z/dsr9soqbf">https://godbolt.org/z/dsr9soqbf</a>
"armv8-a clang (trunk)" exhibits the same problem.</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>