[llvm-bugs] [Bug 51773] New: [arm] Incorrect result with optimizations

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Sep 6 18:59:10 PDT 2021


https://bugs.llvm.org/show_bug.cgi?id=51773

            Bug ID: 51773
           Summary: [arm] Incorrect result with optimizations
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C
          Assignee: unassignedclangbugs at nondot.org
          Reporter: 499537630 at qq.com
                CC: blitzrakete at gmail.com, dgregor at apple.com,
                    erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
                    richard-llvm at metafoo.co.uk

Created attachment 25234
  --> https://bugs.llvm.org/attachment.cgi?id=25234&action=edit
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.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20210907/fe5f94a2/attachment.html>


More information about the llvm-bugs mailing list