Skip to content

ICE on invalid size/alignment in CTFE validation #86193

Closed
@RalfJung

Description

@RalfJung

The following code ICEs:

#[repr(transparent)]
struct W<T>(T);

// The drop fn is checked before size/align are, so get ourselves a "sufficiently valid" drop fn
fn drop_me(_: *mut usize) {}

const INVALID_VTABLE_SIZE: W<&dyn Send> =
    unsafe { std::mem::transmute((&92u8, &(drop_me as fn(*mut usize), usize::MAX, 1usize))) };

To fix this, this code here needs to properly catch the "invalid size/align" error and turn it into a validation failure:

self.ecx.read_size_and_align_from_vtable(vtable),

But for this we first need to make these errors catchable by introducing separate variants into this enum:

pub enum UndefinedBehaviorInfo<'tcx> {

You can use the existing InvalidDropFn variant as a model; it does the same job for invalid drop function pointers in the vtable.

Cc @lqd

Metadata

Metadata

Assignees

Labels

A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️glacierICE tracked in rust-lang/glacier.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions