<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 - Enabling UseAA in the arm backend generates wrong instruction order for pattern initialization"
   href="https://bugs.llvm.org/show_bug.cgi?id=45035">45035</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Enabling UseAA in the arm backend generates wrong instruction order for pattern initialization
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>new-bugs
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </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>new bugs
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>yabinc@google.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>htmldeveloper@gmail.com, llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre><a href="https://reviews.llvm.org/D69796">https://reviews.llvm.org/D69796</a> enables UseAA in the arm backend.
When compiling for arm target on Android with -ftrivial-auto-var-init=pattern,
we found a case that clang generates wrong instruction order to initialize a
local variable, putting a pattern initialization instruction after
initialization instructions in the inlined constructor. Thus it makes a wrongly
initialized member value for the local variable.

An example is shown in <a href="https://godbolt.org/z/3EHgBy">https://godbolt.org/z/3EHgBy</a>.

C++ code:
struct af {
  long long s;
  long long ag;
  bool t;
  bool ah;
  bool u;
  af() : s(0), ag(0), t(false), ah(false), u(false) {}
};
z v, w;
ad x;
void aj(h<void(af &)> &ak) {
  for (; v != w;) {
    af a;
    ak(a);
  }
}

In the for loop, a.t should be initialized to false in the constructor. But
it isn't the case when compiled with below flags:
-c  -mthumb -Os    -O2 -g   -ftrivial-auto-var-init=pattern   -march=armv8-a
-mfloat-abi=softfp -mfpu=neon-fp-armv8  -target armv7a-linux-androideabi10000 
-Wall -Werror -std=gnu++17

In the disassembly:
        mov.w   r5, #-1
        ...
        strd    r5, r5, [sp, #8]    <== pattern initialization
        strd    r5, r5, [sp]        <== pattern initialization
        mov     r1, r9
        vst1.64 {d8, d9}, [r0], r10  <== constructor
        str.w   r11, [r0]            <== constructor
        mov     r0, r8
        strd    r5, r5, [sp, #16]    <== pattern initialization 
        bl      h<void (af&)>::operator()(af&)


So the last pattern initialization instruction makes a.t = 0xff.

The problem goes away if we revert <a href="https://reviews.llvm.org/D69796">https://reviews.llvm.org/D69796</a>.
It is reproduced with latest llvm, with git hash
e4a9225f5d10f35cf9cf3664bb93620880228782.</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>