Eli Friedman | 2fe3636 | 2011-09-27 19:12:27 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -emit-llvm-only -triple i686-pc-win32 -fdump-record-layouts -cxx-abi microsoft %s 2>&1 \ |
| 2 | // RUN: | FileCheck %s |
| 3 | |
| 4 | #pragma pack(push, 8) |
| 5 | |
| 6 | class B { |
| 7 | public: |
| 8 | virtual void b(){} |
| 9 | int b_field; |
| 10 | protected: |
| 11 | private: |
| 12 | }; |
| 13 | |
| 14 | class A : public B { |
| 15 | public: |
| 16 | int a_field; |
| 17 | virtual void a(){} |
| 18 | char one; |
| 19 | protected: |
| 20 | private: |
| 21 | }; |
| 22 | |
| 23 | class D { |
| 24 | public: |
| 25 | virtual void b(){} |
| 26 | double a; |
| 27 | }; |
| 28 | |
| 29 | class C : public virtual A, |
| 30 | public D, public B { |
| 31 | public: |
| 32 | double c1_field; |
| 33 | int c2_field; |
| 34 | double c3_field; |
| 35 | int c4_field; |
| 36 | virtual void foo(){} |
| 37 | virtual void bar(){} |
| 38 | protected: |
| 39 | private: |
| 40 | }; |
| 41 | |
| 42 | struct BaseStruct |
| 43 | { |
| 44 | BaseStruct(){} |
| 45 | double v0; |
| 46 | float v1; |
| 47 | C fg; |
| 48 | }; |
| 49 | |
| 50 | struct DerivedStruct : public BaseStruct { |
| 51 | int x; |
| 52 | }; |
| 53 | |
| 54 | struct G |
| 55 | { |
Eli Friedman | 97c0aef | 2011-10-18 00:55:28 +0000 | [diff] [blame] | 56 | int g_field; |
| 57 | }; |
| 58 | |
| 59 | struct H : public G, |
| 60 | public virtual D |
| 61 | { |
Eli Friedman | 2fe3636 | 2011-09-27 19:12:27 +0000 | [diff] [blame] | 62 | }; |
| 63 | |
Eli Friedman | 227e483 | 2011-10-21 22:49:56 +0000 | [diff] [blame^] | 64 | struct I : public virtual D |
| 65 | { |
| 66 | virtual ~I(){} |
| 67 | double q; |
| 68 | }; |
| 69 | |
Eli Friedman | 2fe3636 | 2011-09-27 19:12:27 +0000 | [diff] [blame] | 70 | #pragma pack(pop) |
| 71 | |
| 72 | // This needs only for building layouts. |
| 73 | // Without this clang doesn`t dump record layouts. |
| 74 | int main() { |
| 75 | // This avoid "Can't yet mangle constructors!" for MS ABI. |
| 76 | C* c; |
| 77 | c->foo(); |
| 78 | DerivedStruct* v; |
Eli Friedman | 97c0aef | 2011-10-18 00:55:28 +0000 | [diff] [blame] | 79 | H* g; |
Eli Friedman | 2fe3636 | 2011-09-27 19:12:27 +0000 | [diff] [blame] | 80 | BaseStruct* u; |
Eli Friedman | 227e483 | 2011-10-21 22:49:56 +0000 | [diff] [blame^] | 81 | I* i; |
Eli Friedman | 2fe3636 | 2011-09-27 19:12:27 +0000 | [diff] [blame] | 82 | return 0; |
| 83 | } |
| 84 | |
| 85 | // CHECK: 0 | class D |
Eli Friedman | 227e483 | 2011-10-21 22:49:56 +0000 | [diff] [blame^] | 86 | // CHECK-NEXT: 0 | (D vftable pointer) |
Eli Friedman | 2fe3636 | 2011-09-27 19:12:27 +0000 | [diff] [blame] | 87 | // CHECK-NEXT: 8 | double a |
| 88 | |
| 89 | // CHECK-NEXT: sizeof=16, dsize=16, align=8 |
| 90 | // CHECK-NEXT: nvsize=16, nvalign=8 |
| 91 | |
| 92 | // CHECK: 0 | class B |
Eli Friedman | 227e483 | 2011-10-21 22:49:56 +0000 | [diff] [blame^] | 93 | // CHECK-NEXT: 0 | (B vftable pointer) |
Eli Friedman | 2fe3636 | 2011-09-27 19:12:27 +0000 | [diff] [blame] | 94 | // CHECK-NEXT: 4 | int b_field |
| 95 | |
| 96 | // CHECK-NEXT: sizeof=8, dsize=8, align=4 |
| 97 | // CHECK-NEXT: nvsize=8, nvalign=4 |
| 98 | |
| 99 | // CHECK: 0 | class A |
| 100 | // CHECK-NEXT: 0 | class B (primary base) |
Eli Friedman | 227e483 | 2011-10-21 22:49:56 +0000 | [diff] [blame^] | 101 | // CHECK-NEXT: 0 | (B vftable pointer) |
Eli Friedman | 2fe3636 | 2011-09-27 19:12:27 +0000 | [diff] [blame] | 102 | // CHECK-NEXT: 4 | int b_field |
| 103 | // CHECK-NEXT: 8 | int a_field |
| 104 | // CHECK-NEXT: 12 | char one |
| 105 | |
| 106 | // CHECK-NEXT: sizeof=16, dsize=16, align=4 |
| 107 | // CHECK-NEXT: nvsize=16, nvalign=4 |
| 108 | |
| 109 | // CHECK: 0 | class C |
| 110 | // CHECK-NEXT: 0 | class D (primary base) |
Eli Friedman | 227e483 | 2011-10-21 22:49:56 +0000 | [diff] [blame^] | 111 | // CHECK-NEXT: 0 | (D vftable pointer) |
Eli Friedman | 2fe3636 | 2011-09-27 19:12:27 +0000 | [diff] [blame] | 112 | // CHECK-NEXT: 8 | double a |
| 113 | // CHECK-NEXT: 16 | class B (base) |
Eli Friedman | 227e483 | 2011-10-21 22:49:56 +0000 | [diff] [blame^] | 114 | // CHECK-NEXT: 16 | (B vftable pointer) |
Eli Friedman | 2fe3636 | 2011-09-27 19:12:27 +0000 | [diff] [blame] | 115 | // CHECK-NEXT: 20 | int b_field |
| 116 | // CHECK-NEXT: 24 | (C vbtable pointer) |
| 117 | // CHECK-NEXT: 32 | double c1_field |
| 118 | // CHECK-NEXT: 40 | int c2_field |
| 119 | // CHECK-NEXT: 48 | double c3_field |
| 120 | // CHECK-NEXT: 56 | int c4_field |
| 121 | // CHECK-NEXT: 64 | class A (virtual base) |
| 122 | // CHECK-NEXT: 64 | class B (primary base) |
Eli Friedman | 227e483 | 2011-10-21 22:49:56 +0000 | [diff] [blame^] | 123 | // CHECK-NEXT: 64 | (B vftable pointer) |
Eli Friedman | 2fe3636 | 2011-09-27 19:12:27 +0000 | [diff] [blame] | 124 | // CHECK-NEXT: 68 | int b_field |
| 125 | // CHECK-NEXT: 72 | int a_field |
| 126 | // CHECK-NEXT: 76 | char one |
| 127 | |
| 128 | // CHECK-NEXT: sizeof=80, dsize=80, align=8 |
Eli Friedman | 227e483 | 2011-10-21 22:49:56 +0000 | [diff] [blame^] | 129 | // CHECK-NEXT: nvsize=64, nvalign=8 |
Eli Friedman | 2fe3636 | 2011-09-27 19:12:27 +0000 | [diff] [blame] | 130 | |
| 131 | // CHECK: 0 | struct BaseStruct |
| 132 | // CHECK-NEXT: 0 | double v0 |
| 133 | // CHECK-NEXT: 8 | float v1 |
| 134 | // CHECK-NEXT: 16 | class C fg |
| 135 | // CHECK-NEXT: 16 | class D (primary base) |
Eli Friedman | 227e483 | 2011-10-21 22:49:56 +0000 | [diff] [blame^] | 136 | // CHECK-NEXT: 16 | (D vftable pointer) |
Eli Friedman | 2fe3636 | 2011-09-27 19:12:27 +0000 | [diff] [blame] | 137 | // CHECK-NEXT: 24 | double a |
| 138 | // CHECK-NEXT: 32 | class B (base) |
Eli Friedman | 227e483 | 2011-10-21 22:49:56 +0000 | [diff] [blame^] | 139 | // CHECK-NEXT: 32 | (B vftable pointer) |
Eli Friedman | 2fe3636 | 2011-09-27 19:12:27 +0000 | [diff] [blame] | 140 | // CHECK-NEXT: 36 | int b_field |
| 141 | // CHECK-NEXT: 40 | (C vbtable pointer) |
| 142 | // CHECK-NEXT: 48 | double c1_field |
| 143 | // CHECK-NEXT: 56 | int c2_field |
| 144 | // CHECK-NEXT: 64 | double c3_field |
| 145 | // CHECK-NEXT: 72 | int c4_field |
| 146 | // CHECK-NEXT: 80 | class A (virtual base) |
| 147 | // CHECK-NEXT: 80 | class B (primary base) |
Eli Friedman | 227e483 | 2011-10-21 22:49:56 +0000 | [diff] [blame^] | 148 | // CHECK-NEXT: 80 | (B vftable pointer) |
Eli Friedman | 2fe3636 | 2011-09-27 19:12:27 +0000 | [diff] [blame] | 149 | // CHECK-NEXT: 84 | int b_field |
| 150 | // CHECK-NEXT: 88 | int a_field |
| 151 | // CHECK-NEXT: 92 | char one |
| 152 | |
| 153 | // CHECK-NEXT: sizeof=80, dsize=80, align=8 |
Eli Friedman | 227e483 | 2011-10-21 22:49:56 +0000 | [diff] [blame^] | 154 | // CHECK-NEXT: nvsize=64, nvalign=8 |
Eli Friedman | 2fe3636 | 2011-09-27 19:12:27 +0000 | [diff] [blame] | 155 | |
| 156 | // CHECK: sizeof=96, dsize=96, align=8 |
| 157 | // CHECK-NEXT: nvsize=96, nvalign=8 |
| 158 | |
| 159 | // CHECK: 0 | struct DerivedStruct |
| 160 | // CHECK-NEXT: 0 | struct BaseStruct (base) |
| 161 | // CHECK-NEXT: 0 | double v0 |
| 162 | // CHECK-NEXT: 8 | float v1 |
| 163 | // CHECK-NEXT: 16 | class C fg |
| 164 | // CHECK-NEXT: 16 | class D (primary base) |
Eli Friedman | 227e483 | 2011-10-21 22:49:56 +0000 | [diff] [blame^] | 165 | // CHECK-NEXT: 16 | (D vftable pointer) |
Eli Friedman | 2fe3636 | 2011-09-27 19:12:27 +0000 | [diff] [blame] | 166 | // CHECK-NEXT: 24 | double a |
| 167 | // CHECK-NEXT: 32 | class B (base) |
Eli Friedman | 227e483 | 2011-10-21 22:49:56 +0000 | [diff] [blame^] | 168 | // CHECK-NEXT: 32 | (B vftable pointer) |
Eli Friedman | 2fe3636 | 2011-09-27 19:12:27 +0000 | [diff] [blame] | 169 | // CHECK-NEXT: 36 | int b_field |
| 170 | // CHECK-NEXT: 40 | (C vbtable pointer) |
| 171 | // CHECK-NEXT: 48 | double c1_field |
| 172 | // CHECK-NEXT: 56 | int c2_field |
| 173 | // CHECK-NEXT: 64 | double c3_field |
| 174 | // CHECK-NEXT: 72 | int c4_field |
| 175 | // CHECK-NEXT: 80 | class A (virtual base) |
| 176 | // CHECK-NEXT: 80 | class B (primary base) |
Eli Friedman | 227e483 | 2011-10-21 22:49:56 +0000 | [diff] [blame^] | 177 | // CHECK-NEXT: 80 | (B vftable pointer) |
Eli Friedman | 2fe3636 | 2011-09-27 19:12:27 +0000 | [diff] [blame] | 178 | // CHECK-NEXT: 84 | int b_field |
| 179 | // CHECK-NEXT: 88 | int a_field |
| 180 | // CHECK-NEXT: 92 | char one |
| 181 | // CHECK-NEXT: sizeof=80, dsize=80, align=8 |
Eli Friedman | 227e483 | 2011-10-21 22:49:56 +0000 | [diff] [blame^] | 182 | // CHECK-NEXT: nvsize=64, nvalign=8 |
Eli Friedman | 2fe3636 | 2011-09-27 19:12:27 +0000 | [diff] [blame] | 183 | |
| 184 | // CHECK: 96 | int x |
| 185 | // CHECK-NEXT: sizeof=104, dsize=104, align=8 |
| 186 | // CHECK-NEXT: nvsize=104, nvalign=8 |
Eli Friedman | 97c0aef | 2011-10-18 00:55:28 +0000 | [diff] [blame] | 187 | |
| 188 | // CHECK: 0 | struct G |
| 189 | // CHECK-NEXT: 0 | int g_field |
| 190 | // CHECK-NEXT: sizeof=4, dsize=4, align=4 |
| 191 | // CHECK-NEXT: nvsize=4, nvalign=4 |
| 192 | |
Eli Friedman | 97c0aef | 2011-10-18 00:55:28 +0000 | [diff] [blame] | 193 | // CHECK: 0 | struct H |
Eli Friedman | 97c0aef | 2011-10-18 00:55:28 +0000 | [diff] [blame] | 194 | // CHECK-NEXT: 0 | struct G (base) |
| 195 | // CHECK-NEXT: 0 | int g_field |
Eli Friedman | 227e483 | 2011-10-21 22:49:56 +0000 | [diff] [blame^] | 196 | // CHECK-NEXT: 4 | (H vbtable pointer) |
Eli Friedman | 97c0aef | 2011-10-18 00:55:28 +0000 | [diff] [blame] | 197 | // CHECK-NEXT: 8 | class D (virtual base) |
Eli Friedman | 227e483 | 2011-10-21 22:49:56 +0000 | [diff] [blame^] | 198 | // CHECK-NEXT: 8 | (D vftable pointer) |
Eli Friedman | 97c0aef | 2011-10-18 00:55:28 +0000 | [diff] [blame] | 199 | // CHECK-NEXT: 16 | double a |
| 200 | // CHECK-NEXT: sizeof=24, dsize=24, align=8 |
Eli Friedman | 227e483 | 2011-10-21 22:49:56 +0000 | [diff] [blame^] | 201 | // CHECK-NEXT: nvsize=8, nvalign=4 |
| 202 | |
| 203 | // CHECK: 0 | struct I |
| 204 | // CHECK-NEXT: 0 | (I vftable pointer) |
| 205 | // CHECK-NEXT: 8 | (I vbtable pointer) |
| 206 | // CHECK-NEXT: 16 | double q |
| 207 | // CHECK-NEXT: 24 | class D (virtual base) |
| 208 | // CHECK-NEXT: 24 | (D vftable pointer) |
| 209 | // CHECK-NEXT: 32 | double a |
| 210 | // CHECK-NEXT: sizeof=40, dsize=40, align=8 |
Eli Friedman | 97c0aef | 2011-10-18 00:55:28 +0000 | [diff] [blame] | 211 | // CHECK-NEXT: nvsize=24, nvalign=8 |