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: [email protected]
          Reporter: [email protected]
                CC: [email protected]

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.
_______________________________________________
llvm-bugs mailing list
[email protected]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to