Skip to content

ui/unsafe/union.rs test has UB #95075

@bjorn3

Description

@bjorn3
Member

https://github.com/rust-lang/rust/blob/691d1c1e12602c57237e9ccddac406ebd0c54082/src/test/ui/unsafe/union.rs

Running it in miri gives the following error:

error: Undefined Behavior: enum value has invalid tag: 0x07
  --> example/union.rs:49:15
   |
49 |         match foo {
   |               ^^^ enum value has invalid tag: 0x07
   |
   = help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
   = help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
           
   = note: inside `main` at example/union.rs:49:15

note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace

I found this issue because cg_clif aborts matching on an invalid discriminant.

cc @Smittyvb as you introduced this test.

Activity

added
C-bugCategory: This is a bug.
A-craneliftThings relevant to the [future] cranelift backend
on Mar 18, 2022
syvb

syvb commented on Mar 19, 2022

@syvb
Contributor

@rustbot claim

I forgot that the test actually got executed, I'll make a PR to move the UB parts to a check-pass test.

added a commit that references this issue on Mar 21, 2022
44628f7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-craneliftThings relevant to the [future] cranelift backendC-bugCategory: This is a bug.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    Participants

    @syvb@bjorn3

    Issue actions

      ui/unsafe/union.rs test has UB · Issue #95075 · rust-lang/rust