<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/153331>153331</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[Clang] `-fdump-record-layouts` prints in the wrong order
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
kon72
</td>
</tr>
</table>
<pre>
The offsets of class C2 are out of order.
(This code is taken from https://itanium-cxx-abi.github.io/cxx-abi/abi.html#vtable-ctor-vtt)
```test.cpp
class A1 { int i; };
class A2 { int i; virtual void f(); };
class V1 : public A1, public A2 { int i; };
// A2 is primary base of V1, A1 is non-polymorphic
class B1 { int i; };
class B2 { int i; };
class V2 : public B1, public B2, public virtual V1 { int i; };
// V2 has no primary base, V1 is secondary base
class V3 { virtual void g(); };
class C2 : public virtual V3, public virtual V2 { int i; };
C2 c2;
```
Actual output:
```
*** Dumping AST Record Layout
0 | class V3
0 | (V3 vtable pointer)
| [sizeof=8, dsize=8, align=8,
| nvsize=8, nvalign=8]
*** Dumping AST Record Layout
0 | class B1
0 | int i
| [sizeof=4, dsize=4, align=4,
| nvsize=4, nvalign=4]
*** Dumping AST Record Layout
0 | class B2
0 | int i
| [sizeof=4, dsize=4, align=4,
| nvsize=4, nvalign=4]
*** Dumping AST Record Layout
0 | class A1
0 | int i
| [sizeof=4, dsize=4, align=4,
| nvsize=4, nvalign=4]
*** Dumping AST Record Layout
0 | class A2
0 | (A2 vtable pointer)
8 | int i
| [sizeof=16, dsize=12, align=8,
| nvsize=12, nvalign=8]
*** Dumping AST Record Layout
0 | class V1
0 | class A2 (primary base)
0 | (A2 vtable pointer)
8 | int i
12 | class A1 (base)
12 | int i
16 | int i
| [sizeof=24, dsize=20, align=8,
| nvsize=20, nvalign=8]
*** Dumping AST Record Layout
0 | class V2
0 | (V2 vtable pointer)
8 | class B1 (base)
8 | int i
12 | class B2 (base)
12 | int i
16 | int i
24 | class V1 (virtual base)
24 | class A2 (primary base)
24 | (A2 vtable pointer)
32 | int i
36 | class A1 (base)
36 | int i
40 | int i
| [sizeof=48, dsize=44, align=8,
| nvsize=20, nvalign=8]
*** Dumping AST Record Layout
0 | class C2
8 | int i
0 | class V3 (primary virtual base)
0 | (V3 vtable pointer)
40 | class V1 (virtual base)
40 | class A2 (primary base)
40 | (A2 vtable pointer)
48 | int i
52 | class A1 (base)
52 | int i
56 | int i
16 | class V2 (virtual base)
16 | (V2 vtable pointer)
24 | class B1 (base)
24 | int i
28 | class B2 (base)
28 | int i
32 | int i
| [sizeof=64, dsize=60, align=8,
| nvsize=12, nvalign=8]
```
---
```
$ /opt/homebrew/opt/llvm/bin/clang -v
Homebrew clang version 20.1.8
Target: arm64-apple-darwin24.5.0
Thread model: posix
InstalledDir: /opt/homebrew/Cellar/llvm/20.1.8/bin
Configuration file: /opt/homebrew/etc/clang/arm64-apple-darwin24.cfg
System configuration file directory: /opt/homebrew/etc/clang
User configuration file directory: /Users/kon/.config/clang
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzUWE3PozYQ_jXOZURkzEfIIQeSKGqlnrpvczdgwF2DkW2y-_bXVwaSwBvIZle7qhrlYns888wzHzamWvOiZmyHgj0KjivamlKq3WdZb8gqkdn77q1kIPNcM6NB5pAKqjUcCFDFQLbGzkmVMbVGOLZ_Er2VXEMqMwZcg6GfWQ25khWUxjQaeTEiJ0RO3NCat5WTfv3q0ISvC27KNllzichpmEPkZFdKUwlEvIuhiWBOaqRyLsYgsh0shrj_G6bNOm0ahOMeZewC2uyB1wY48vaANkfk7e_LZLp84cq0VMBF8gxyRCJr4nHb2QXkxdC0ieApxC4ih9uALBjsXbbrXEOjeEXVOyRUW2rh3KmIXbtWy9pppHivpGpKnvYe9nb3z73ZL9keUJMx6v0Y9Z6MBlcSzkvWBlfOBEpq8U7csYrOnSOapbLObvMjP85ep3nCdrHI9mGC-4bOm4O8yD6ODwRSMoyu-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