<html>
<head>
<base href="http://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 --- - [-cxx-abi microsoft] clang calculates size wrong of struct with field of struct type with aligned field"
href="http://llvm.org/bugs/show_bug.cgi?id=18027">18027</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>[-cxx-abi microsoft] clang calculates size wrong of struct with field of struct type with aligned field
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>All
</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>LLVM Codegen
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>david.majnemer@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvmbugs@cs.uiuc.edu
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>#include <stddef.h>
#include <stdio.h>
#include <string.h>
char buffer[419430400];
inline void *operator new(size_t, void *pv) { return pv; }
struct ClassName0 {
int ClassName0FieldName0;
ClassName0() {
printf("ClassName0FieldName0 : %llu\n", (unsigned long
long)((size_t)&ClassName0FieldName0 - (size_t)buffer));
}
};
struct ClassName1: public virtual ClassName0 {
__declspec(align(512)) short ClassName1FieldName0;
ClassName1() {
printf("ClassName1FieldName0 : %llu\n", (unsigned long
long)((size_t)&ClassName1FieldName0 - (size_t)buffer));
}
};
struct ClassName2: public virtual ClassName0 {
ClassName1 ClassName2FieldName0;
ClassName2() {
printf("ClassName2FieldName0 : %llu\n", (unsigned long
long)((size_t)&ClassName2FieldName0 - (size_t)buffer));
}
};
struct ClassName3: public virtual ClassName1, public virtual ClassName2 {
int ClassName3FieldName0;
ClassName3() {
printf("ClassName3FieldName0 : %llu\n", (unsigned long
long)((size_t)&ClassName3FieldName0 - (size_t)buffer));
}
};
int main() {
memset(buffer, 0, sizeof(buffer));
new (buffer) ClassName0;
printf(" sizeof(ClassName0): %Iu\n", sizeof(ClassName0));
printf("__alignof(ClassName0): %Iu\n", __alignof(ClassName0));
memset(buffer, 0, sizeof(buffer));
new (buffer) ClassName1;
printf(" sizeof(ClassName1): %Iu\n", sizeof(ClassName1));
printf("__alignof(ClassName1): %Iu\n", __alignof(ClassName1));
memset(buffer, 0, sizeof(buffer));
new (buffer) ClassName2;
printf(" sizeof(ClassName2): %Iu\n", sizeof(ClassName2));
printf("__alignof(ClassName2): %Iu\n", __alignof(ClassName2));
memset(buffer, 0, sizeof(buffer));
new (buffer) ClassName3;
printf(" sizeof(ClassName3): %Iu\n", sizeof(ClassName3));
printf("__alignof(ClassName3): %Iu\n", __alignof(ClassName3));
}
msvc:
ClassName0FieldName0 : 0
sizeof(ClassName0): 4
__alignof(ClassName0): 4
ClassName0FieldName0 : 1024
ClassName1FieldName0 : 512
sizeof(ClassName1): 1536
__alignof(ClassName1): 512
ClassName0FieldName0 : 2048
ClassName0FieldName0 : 1536
ClassName1FieldName0 : 1024
ClassName2FieldName0 : 512
sizeof(ClassName2): 2560
__alignof(ClassName2): 512
ClassName0FieldName0 : 8
ClassName1FieldName0 : 1024
ClassName0FieldName0 : 3072
ClassName1FieldName0 : 2560
ClassName2FieldName0 : 2048
ClassName3FieldName0 : 4
sizeof(ClassName3): 3584
__alignof(ClassName3): 512
clang:
ClassName0FieldName0 : 0
sizeof(ClassName0): 4
__alignof(ClassName0): 4
ClassName0FieldName0 : 1024
ClassName1FieldName0 : 512
sizeof(ClassName1): 1536
__alignof(ClassName1): 512
ClassName0FieldName0 : 2048
ClassName0FieldName0 : 1536
ClassName1FieldName0 : 1024
ClassName2FieldName0 : 512
sizeof(ClassName2): 2052
__alignof(ClassName2): 512
ClassName0FieldName0 : 8
ClassName1FieldName0 : 1024
ClassName0FieldName0 : 3072
ClassName1FieldName0 : 2560
ClassName2FieldName0 : 2048
ClassName3FieldName0 : 4
sizeof(ClassName3): 3584
__alignof(ClassName3): 512</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>