nomicon icon indicating copy to clipboard operation
nomicon copied to clipboard

significantly cleanup and flesh out page on UB

Open Gankra opened this issue 6 years ago • 7 comments

Gankra avatar Aug 16 '19 13:08 Gankra

this is a followup on #149

cc @RalfJung: welcome to round 2, fight me

Gankra avatar Aug 16 '19 13:08 Gankra

Extremely Rough Note before I wander off: I feel like I want to define a concrete notion of two different ways a type can occupy memory to address how unions/enums have a strange relationship with uninit memory.

Perhaps it's sufficient to just appeal to size vs "actual" memory? I believe we do not actually require/guarantee that e.g. moving an Option<u32> moves the memory footprint of the Some variant (ignoring the specific ongoing discussion of ptr::copy and padding which is weird).

Like it should be fine for us to check/know that the variant is None and just copy the tag. Too dizzy to think and need to bounce.

Gankra avatar Aug 16 '19 13:08 Gankra

I believe we do not actually require/guarantee that e.g. moving an Option moves the memory footprint of the Some variant (ignoring the specific ongoing discussion of ptr::copy and padding which is weird).

Indeed, padding does not have to be copied. Some UCG resources on this:

  • https://github.com/rust-lang/unsafe-code-guidelines/issues/183
  • https://github.com/rust-lang/unsafe-code-guidelines/pull/195
  • My value domain proposal has a notion of "typed copy" that both handles "invalid data is UB" and "padding does not have to be copied".

RalfJung avatar Aug 16 '19 15:08 RalfJung

Should there be a mention that null vtable pointers for even trait object raw pointers (And not just references which I believe could be understood from https://github.com/rust-lang-nursery/nomicon/pull/149/files#diff-9f9e3daa6dcba4f53211916eb094e123R37) are UB (Which iirc they are. Like in https://play.rust-lang.org/?version=stable&mode=release&edition=2018&gist=82583ed18f9d0891adb54e5403269dec . https://github.com/rust-lang/rfcs/issues/433#issuecomment-345497470 says it is).

nico-abram avatar Aug 24 '19 04:08 nico-abram

@nico-abram Agreed -- if we decide that we really want this non-NULL property, we should add it here. But I don't think this is clear-cut yet.

RalfJung avatar Aug 24 '19 14:08 RalfJung

Wouldn't being conservative on what's considered UB be best?

nico-abram avatar Aug 24 '19 17:08 nico-abram

Fair. In my mind this is still a rustc bug but I guess many won't agree. ;)

RalfJung avatar Aug 24 '19 18:08 RalfJung