[llvm-bugs] [Bug 36076] New: Stores to union incorrectly reordered

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Jan 24 08:02:39 PST 2018


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

            Bug ID: 36076
           Summary: Stores to union incorrectly reordered
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Scalar Optimizations
          Assignee: unassignedbugs at nondot.org
          Reporter: momchil.velikov at arm.com
                CC: llvm-bugs at lists.llvm.org

Created attachment 19739
  --> https://bugs.llvm.org/attachment.cgi?id=19739&action=edit
minimal testcase

The attached test program is mis-compiled at all optimisation levels, except
-O0, for X86_64, Arm and likely for all targets.

./bin/clang -target x86_64-linux -O2 union-store.c
$ ./a.out 
value = 3, should be 2

This happens in Dead Store Elimination:

*** IR Dump After Value Propagation ***
; Function Attrs: norecurse nounwind
define void @f() local_unnamed_addr #0 {
entry:
  store i32 5, i32* getelementptr inbounds (%union.U, %union.U* @a, i32 0, i32
0), align 4, !tbaa !3
  %0 = load i16*, i16** bitcast (%union.U** @b to i16**), align 4, !tbaa !6
  store i16 3, i16* %0, align 4, !tbaa !3
  store i16 2, i16* bitcast (%union.U* @a to i16*), align 4, !tbaa !3
  ret void
}
*** IR Dump After Dead Store Elimination ***
; Function Attrs: norecurse nounwind
define void @f() local_unnamed_addr #0 {
entry:
  store i32 2, i32* getelementptr inbounds (%union.U, %union.U* @a, i32 0, i32
0), align 4, !tbaa !3
  %0 = load i16*, i16** bitcast (%union.U** @b to i16**), align 4, !tbaa !6
  store i16 3, i16* %0, align 4, !tbaa !3
  ret void
}

-- 
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/20180124/8fa450fc/attachment.html>


More information about the llvm-bugs mailing list