<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </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 --- - 8-bit and 16-bit atomic operations return wrongly extended results"
   href="https://llvm.org/bugs/show_bug.cgi?id=27599">27599</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>8-bit and 16-bit atomic operations return wrongly extended results
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

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

        <tr>
          <th>Hardware</th>
          <td>Other
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

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

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>Backend: SystemZ
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>koriakin@0x04.net
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>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.</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>