Skip to content

Seeing ICE due to u32 overflow #214

@smklein

Description

@smklein

I have a repo I'm attempting to profile with these instructions: https://blog.rust-lang.org/inside-rust/2020/02/25/intro-rustc-self-profile.html#profiling-the-compiler

cargo +nightly rustc --lib -- -Zself-profile -Zself-profile-events=default,args

This results in the following output:

thread 'rustc' panicked at /rust/deps/measureme-10.1.1/src/stringtable.rs:105:62:                                                                                                                                                                                                                                                                                                                                                                               
called `Option::unwrap()` on a `None`

Which appears to be the unwrap within:

#[inline]
pub fn from_addr(addr: Addr) -> StringId {
let id = addr.0.checked_add(FIRST_REGULAR_STRING_ID).unwrap();
StringId::new(id)
}

I noticed that the type of StringId is a u32:

pub struct StringId(u32);

And since we're calling from_addr, we care about that type too:

/// An address within a data stream. Each data stream has its own address space,
/// i.e. the first piece of data written to the events stream will have
/// `Addr(0)` and the first piece of data written to the string data stream
/// will *also* have `Addr(0)`.
//
// TODO: Evaluate if it makes sense to add a type tag to `Addr` in order to
// prevent accidental use of `Addr` values with the wrong address space.
#[derive(Clone, Copy, Eq, PartialEq, Debug)]
pub struct Addr(pub u32);

Why do we believe this will be limited to u32? As a small data point, the "...mm_profdata" file I was emitting looks like it's just over 4 GiB in size, which sorta aligns with the idea of a u32 overflow.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions