[LLVMbugs] [Bug 18826] New: MS ABI: clang doesn't create a packed struct when one is required

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Wed Feb 12 23:04:57 PST 2014


http://llvm.org/bugs/show_bug.cgi?id=18826

            Bug ID: 18826
           Summary: MS ABI: clang doesn't create a packed struct when one
                    is required
           Product: clang
           Version: unspecified
          Hardware: PC
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: LLVM Codegen
          Assignee: unassignedclangbugs at nondot.org
          Reporter: david.majnemer at gmail.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

consider:
extern "C" int printf(const char *, ...);
char buffer[1 << 10];
struct A {
  A() {
    printf("A       : %u\n", (char *)this - buffer);
  }
};
struct B {
  bool BField;
  B() {
    printf("B       : %u\n", (char *)this - buffer);
    printf("BField  : %u\n", (char *)&BField - buffer);
  }
};
struct C : virtual A, virtual B {
  bool CField;
  C() {
    printf("C       : %u\n", (char *)this - buffer);
    printf("CField  : %u\n", (char *)&CField - buffer);
    printf("A-in-C  : %u\n", (char *)(A *)this - buffer);
    printf("B-in-C  : %u\n", (char *)(B *)this - buffer);
  }
};
struct D : C, A {
  D() {
    printf("D       : %u\n", (char *)this - buffer);
    printf("C-in-D  : %u\n", (char *)(C *)this - buffer);
  }
};
void *operator new(size_t, void *pv) { return buffer; }
int main() {
  printf("sizeof(A): %u\n", sizeof(A));
  printf("sizeof(B): %u\n", sizeof(B));
  printf("sizeof(C): %u\n", sizeof(C));
  printf("sizeof(D): %u\n", sizeof(D));
  new (buffer) D;
}

clang gives us:
sizeof(A): 1
sizeof(B): 1
sizeof(C): 9
sizeof(D): 13
A       : 12
B       : 12
BField  : 12
C       : 0
CField  : 4
A-in-C  : 12
B-in-C  : 12
A       : 9
D       : 0
C-in-D  : 0

msvc gives us:
sizeof(A): 1
sizeof(B): 1
sizeof(C): 9
sizeof(D): 9
A       : 8
B       : 8
BField  : 8
C       : 0
CField  : 4
A-in-C  : 8
B-in-C  : 8
A       : 8
D       : 0
C-in-D  : 0

C's nvsize is 8 in clang

-- 
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/20140213/42c63300/attachment.html>


More information about the llvm-bugs mailing list