<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </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 - wrong code generated for bit field access"
   href="https://bugs.llvm.org/show_bug.cgi?id=45265">45265</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>wrong code generated for bit field access
          </td>
        </tr>

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

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

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

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

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

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

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

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

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

        <tr>
          <th>Reporter</th>
          <td>carrot@google.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>craig.topper@gmail.com, llvm-bugs@lists.llvm.org, llvm-dev@redking.me.uk, spatel+llvm@rotateright.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre>The source code is:

struct S {
  long long f1 : 40;
  long long f2 : 48;
  char f3;
}  __attribute__((__packed__));

extern void foo();

void bar(int i, struct S *p) {
  if (p[i].f2 == i)
    foo();
}

Command line:

clang -c bitfield.c -O3 -save-temps

generates:

# %bb.0:                                # %entry
        movslq  %edi, %rax
        leaq    (%rax,%rax,2), %rcx
        cmpq    %rax, 5(%rsi,%rcx,4)    
        jne     .LBB0_1
# %bb.2:                                # %if.then
        xorl    %eax, %eax
        jmp     foo                     # TAILCALL
.LBB0_1:                                # %if.end
        retq


The access of p[i].f2 should load 48bit value from memory, but instruction
   cmpq    %rax, 5(%rsi,%rcx,4) 
loads 64 bit value from memory and uses it directly. The high 16bit contains
unrelated value, and causes run time error.</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>