<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 - [arm] Incorrect result with optimizations"
   href="https://bugs.llvm.org/show_bug.cgi?id=51773">51773</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[arm] Incorrect result with optimizations
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

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

        <tr>
          <th>OS</th>
          <td>Windows NT
          </td>
        </tr>

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

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>C
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>499537630@qq.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>blitzrakete@gmail.com, dgregor@apple.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=25234" name="attach_25234" title="testcase">attachment 25234</a> <a href="attachment.cgi?id=25234&action=edit" title="testcase">[details]</a></span>
testcase

I have the following test case. The problem occurs on the ARM platform. It
seems that the problem is caused by Clang optimization. I expected to enter the
return 2 elements, but actually enter return only 1 element, which is normal
when optimization(O1 or O2) occurs.

This testcase is simple. The code logic is as follows:
1. The head, node1.node, and node2.node nodes are initialized.
2. Add node1.node to the end of the head, and then add node2.node to the end of
the head. Therefore, the linked list is head->node2.node->node1.node.
3. Traverse the linked list. node1.node and node2.node, are traversed.


$clang --target=arm-linux-eabi -O2 -c os.c -o test.o

error result:
&head = 0x1905c, &node1.node = 0x19044, &node2.done = 0x19054
 head.wNextOfst = -24, node1.node.wNextOfst = 24, node2.node.wNextOfst = 8
list_for_each_safe 1


expected result(O0):
&head = 0x191a4, &node1.node = 0x1918c, &node2.done = 0x1919c
 head.wNextOfst = -24, node1.node.wNextOfst = 16, node2.node.wNextOfst = 8
list_for_each_safe 1
list_for_each_safe 2


Compare the running results. It can be found that the for loop finds node1 and
node2 in the sequence of node1->node2->head. However, after node1 is found, the
head is directly found. So node1.node.wNextOfst is the point. The experted
value is 16 but we get 24.</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>