Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ICE on invalid size/alignment in CTFE validation #86193

Closed
RalfJung opened this issue Jun 10, 2021 · 1 comment · Fixed by #86245
Closed

ICE on invalid size/alignment in CTFE validation #86193

RalfJung opened this issue Jun 10, 2021 · 1 comment · Fixed by #86245
Assignees
Labels
A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@RalfJung
Copy link
Member

RalfJung commented Jun 10, 2021

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

@RalfJung RalfJung added E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) labels Jun 10, 2021
@lqd
Copy link
Member

lqd commented Jun 10, 2021

I'll take care of this

@rustbot claim

fanninpm added a commit to fanninpm/glacier that referenced this issue Jun 11, 2021
@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Jun 12, 2021
@bors bors closed this as completed in fb3ea63 Jun 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants