Skip to content

trans codegen injects aliasing of l-values via match ident { ident => ... } #23698

Closed
@pnkfelix

Description

@pnkfelix

trans codegen feeds the zeroed discriminant back into match in a loop

Some examples, courtesy of @eddyb and @dotdash

fn main() {
    let mut result = Box::new(42);
    let mut i = 0;
    loop {
        match result {
            x => {
                println!("A>>> {:p}", &*x);
                println!("A: {:?}", x);
                result = Box::new(42);
                if i > 10 { break; }
                i += 1;
            }
        }
    }
}

playpen here yields:

A>>> 0x7fedb4423008
A: 42
A>>> 0x0
playpen: application terminated abnormally with signal 4 (Illegal instruction)

Another one, courtesy of @eddyb:

fn main() {
    let mut result = (Box::new(12), 34);

    // Run in a loop to demonstrate the zeroing:
    let mut i = 0;
    while i < 4 {
        match result {
            x => {
                println!("{:p} {}", &*x.0, x.1);
                result = (Box::new(12), 34);
                i += 1;
            }
        }
    }
}

playpen yields:

0x7f05c5823008 34
0x0 0
0x0 0
0x0 0

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