[llvm-bugs] [Bug 45265] New: wrong code generated for bit field access

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Mar 20 15:06:31 PDT 2020


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

            Bug ID: 45265
           Summary: wrong code generated for bit field access
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Backend: X86
          Assignee: unassignedbugs at nondot.org
          Reporter: carrot at google.com
                CC: craig.topper at gmail.com, llvm-bugs at lists.llvm.org,
                    llvm-dev at redking.me.uk, spatel+llvm at rotateright.com

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.

-- 
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/20200320/94e221da/attachment.html>


More information about the llvm-bugs mailing list