Commit 4649877
committed
Auto merge of rust-lang#125479 - scottmcm:validate-vtable-projections, r=Nilstrieb
Validate the special layout restriction on `DynMetadata`
If you look at <https://stdrs.dev/nightly/x86_64-unknown-linux-gnu/std/ptr/struct.DynMetadata.html>, you'd think that `DynMetadata` is a struct with fields.
But it's actually not, because the lang item is special-cased in rustc_middle layout:
https://github.com/rust-lang/rust/blob/7601adcc764d42c9f2984082b49948af652df986/compiler/rustc_middle/src/ty/layout.rs#L861-L864
That explains the very confusing codegen ICEs I was getting in rust-lang#124251 (comment)
> Tried to extract_field 0 from primitive OperandRef(Immediate((ptr: %5 = load ptr, ptr %4, align 8, !nonnull !3, !align !5, !noundef !3)) @ TyAndLayout { ty: DynMetadata<dyn Callsite>, layout: Layout { size: Size(8 bytes), align: AbiAndPrefAlign { abi: Align(8 bytes), pref: Align(8 bytes) }, abi: Scalar(Initialized { value: Pointer(AddressSpace(0)), valid_range: 1..=18446744073709551615 }), fields: Primitive, largest_niche: Some(Niche { offset: Size(0 bytes), value: Pointer(AddressSpace(0)), valid_range: 1..=18446744073709551615 }), variants: Single { index: 0 }, max_repr_align: None, unadjusted_abi_align: Align(8 bytes) } })
because there was a `Field` projection despite the layout clearly saying it's [`Primitive`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_target/abi/enum.FieldsShape.html#variant.Primitive).
Thus this PR updates the MIR validator to check for such a projection, and changes `libcore` to not ever emit any projections into `DynMetadata`, just to transmute the whole thing when it wants a pointer.File tree
2 files changed
+28
-8
lines changed- compiler/rustc_const_eval/src/transform
- library/core/src/ptr
2 files changed
+28
-8
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
685 | 685 | | |
686 | 686 | | |
687 | 687 | | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
688 | 697 | | |
689 | 698 | | |
690 | 699 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
178 | 178 | | |
179 | 179 | | |
180 | 180 | | |
181 | | - | |
182 | | - | |
| 181 | + | |
| 182 | + | |
183 | 183 | | |
184 | 184 | | |
185 | 185 | | |
| |||
191 | 191 | | |
192 | 192 | | |
193 | 193 | | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
194 | 205 | | |
195 | 206 | | |
196 | 207 | | |
| |||
199 | 210 | | |
200 | 211 | | |
201 | 212 | | |
202 | | - | |
| 213 | + | |
203 | 214 | | |
204 | 215 | | |
205 | 216 | | |
| |||
208 | 219 | | |
209 | 220 | | |
210 | 221 | | |
211 | | - | |
| 222 | + | |
212 | 223 | | |
213 | 224 | | |
214 | 225 | | |
| |||
226 | 237 | | |
227 | 238 | | |
228 | 239 | | |
229 | | - | |
| 240 | + | |
230 | 241 | | |
231 | 242 | | |
232 | 243 | | |
| |||
248 | 259 | | |
249 | 260 | | |
250 | 261 | | |
251 | | - | |
| 262 | + | |
252 | 263 | | |
253 | 264 | | |
254 | 265 | | |
255 | 266 | | |
256 | 267 | | |
257 | 268 | | |
258 | 269 | | |
259 | | - | |
| 270 | + | |
260 | 271 | | |
261 | 272 | | |
262 | 273 | | |
| |||
270 | 281 | | |
271 | 282 | | |
272 | 283 | | |
273 | | - | |
| 284 | + | |
274 | 285 | | |
275 | 286 | | |
0 commit comments