Skip to content

possible ASAN miscompile #121028

Closed
Closed
@krasimirgg

Description

@krasimirgg

I tried this code with ASAN nightly rust (https://godbolt.org/z/KE6P9xYsY):

// Doesn't fail without -Copt-level=0

#[repr(C)] // doesn't fail without this
#[derive(Clone, Debug)]
pub enum A {
    A(i8),
}

#[repr(C)]  // doesn't fail without this
pub enum B {
    B(A),
}

// doesn't fail if extern "C" is dropped
pub extern "C" fn f(b: B) -> A {
    let a = match b {
        B::B(a) => Some(a),
    };
    a.unwrap()
}

fn main() {
    let b = B::B(A::A(3));
    // doesn't fail if the body of f is inlined.
    let a = f(b);
    println!("a: {:?}", &a);
}

I expected to see this happen: program executes successfully.

Instead, this happened: program failed with ASAN warning.

Meta

Requires nightly with -Zsanitizer=address --target x86_64-unknown-linux-gnu -Copt-level=0: https://godbolt.org/z/KE6P9xYsY.

It looks this is not a recent regression, it's present in rust from 2021.

% export dt=2021-06-10 ; rustup install nightly-$dt &&  rustc +nightly-$dt  -Zsanitizer=address --target x86_64-unknown-linux-gnu -Copt-level=0 -g main.rs && ./main

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.A-codegenArea: Code generationA-sanitizersArea: Sanitizers for correctness and code qualityC-bugCategory: This is a bug.C-optimizationCategory: An issue highlighting optimization opportunities or PRs implementing suchI-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions