[LLVMbugs] [Bug 18170] New: [-cxx-abi microsoft] Base class with zero width bitfield has improper layout
bugzilla-daemon at llvm.org
bugzilla-daemon at llvm.org
Sat Dec 7 02:34:43 PST 2013
http://llvm.org/bugs/show_bug.cgi?id=18170
Bug ID: 18170
Summary: [-cxx-abi microsoft] Base class with zero width
bitfield has improper layout
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:
#if defined(__clang__) || defined(__GNUC__)
typedef __SIZE_TYPE__ size_t;
#endif
extern "C" int printf(const char *fmt, ...);
extern "C" void *memset(void *ptr, int value, size_t num);
static char buffer[419430400];
inline void *operator new(size_t, void *pv) { return pv; }
struct ClassName0 {
char : 0;
ClassName0() {
}
};
struct ClassName1: public ClassName0 {
char ClassName1FieldName0;
ClassName1() {
printf("ClassName1FieldName0 : %llu\n", (unsigned long
long)((size_t)&ClassName1FieldName0 - (size_t)buffer));
}
};
struct ClassName2: public virtual ClassName1, public ClassName0 {
float ClassName2FieldName0;
float ClassName2FieldName1;
ClassName2() {
printf("ClassName2FieldName0 : %llu\n", (unsigned long
long)((size_t)&ClassName2FieldName0 - (size_t)buffer));
printf("ClassName2FieldName1 : %llu\n", (unsigned long
long)((size_t)&ClassName2FieldName1 - (size_t)buffer));
}
};
struct ClassName3: public virtual ClassName2, public virtual ClassName1 {
bool ClassName3FieldName0;
long long ClassName3FieldName1;
ClassName3() {
printf("ClassName3FieldName0 : %llu\n", (unsigned long
long)((size_t)&ClassName3FieldName0 - (size_t)buffer));
printf("ClassName3FieldName1 : %llu\n", (unsigned long
long)((size_t)&ClassName3FieldName1 - (size_t)buffer));
}
};
static void test_layout(const char *class_name, size_t size_of_class, size_t
align_of_class) {
printf(" sizeof(%s): %Iu\n", class_name, size_of_class);
printf("__alignof(%s): %Iu\n", class_name, align_of_class);
}
template <typename Class>
static void init_mem() {
memset(buffer, 0xcc, sizeof(buffer));
new (buffer) Class;
}
#define test(Class) init_mem<Class>(), test_layout(#Class, sizeof(Class),
__alignof(Class))
int main() {
test(ClassName0);
test(ClassName1);
test(ClassName2);
test(ClassName3);
}
msvc:
sizeof(ClassName0): 1
__alignof(ClassName0): 1
ClassName1FieldName0 : 0
sizeof(ClassName1): 1
__alignof(ClassName1): 1
ClassName1FieldName0 : 12
ClassName2FieldName0 : 4
ClassName2FieldName1 : 8
sizeof(ClassName2): 13
__alignof(ClassName2): 4
ClassName1FieldName0 : 24
ClassName2FieldName0 : 36
ClassName2FieldName1 : 40
ClassName3FieldName0 : 8
ClassName3FieldName1 : 16
sizeof(ClassName3): 44
__alignof(ClassName3): 8
clang:
sizeof(ClassName0): 1
__alignof(ClassName0): 1
ClassName1FieldName0 : 0
sizeof(ClassName1): 1
__alignof(ClassName1): 1
ClassName1FieldName0 : 12
ClassName2FieldName0 : 4
ClassName2FieldName1 : 8
sizeof(ClassName2): 13
__alignof(ClassName2): 4
ClassName1FieldName0 : 24
ClassName2FieldName0 : 40
ClassName2FieldName1 : 44
ClassName3FieldName0 : 8
ClassName3FieldName1 : 16
sizeof(ClassName3): 48
__alignof(ClassName3): 8
--
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/20131207/63c360b1/attachment.html>
More information about the llvm-bugs
mailing list