[llvm-bugs] [Bug 27599] New: 8-bit and 16-bit atomic operations return wrongly extended results

via llvm-bugs llvm-bugs at lists.llvm.org
Mon May 2 02:33:36 PDT 2016


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

            Bug ID: 27599
           Summary: 8-bit and 16-bit atomic operations return wrongly
                    extended results
           Product: libraries
           Version: trunk
          Hardware: Other
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Backend: SystemZ
          Assignee: unassignedbugs at nondot.org
          Reporter: koriakin at 0x04.net
                CC: llvm-bugs at lists.llvm.org
    Classification: Unclassified

The following function:

char f(char *x, char y, char z) {
        return __sync_val_compare_and_swap(x, y, z);
}

compiles to that:

define zeroext i8 @f(i8* nocapture, i8 zeroext, i8 zeroext) #0 {
  %4 = cmpxchg i8* %0, i8 %1, i8 %2 seq_cst seq_cst
  %5 = extractvalue { i8, i1 } %4, 0
  ret i8 %5
}

which compiles to that:

f:                                      # @f
# BB#0:
        stmg    %r13, %r15, 104(%r15)
        risbg   %r1, %r2, 0, 189, 0
        sll     %r2, 3
        lcr     %r5, %r2
        l       %r0, 0(%r1)
.LBB0_1:                                # =>This Inner Loop Header: Depth=1
        rll     %r14, %r0, 8(%r2)
        risbg   %r3, %r14, 32, 55, 0
        crjlh   %r14, %r3, .LBB0_3
# BB#2:                                 #   in Loop: Header=BB0_1 Depth=1
        risbg   %r4, %r14, 32, 55, 0
        rll     %r13, %r4, -8(%r5)
        cs      %r0, %r13, 0(%r1)
        jl      .LBB0_1
.LBB0_3:
        llgfr   %r2, %r14
        lmg     %r13, %r15, 104(%r15)
        br      %r14

The function ends with a llgfr, zero extending i32 to i64 - however, the high
24 bits of %r14 contain junk at this point, so the result will be wrong.  This
breaks ASan tests when the ASan runtime is compiled by clang.

It seems CodeGen assumes that sub-word atomic operations return zero-extended
(or sign-extended if TLI says so) results, and SystemZ doesn't deliver.

-- 
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/20160502/fa722dd1/attachment.html>


More information about the llvm-bugs mailing list