Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LLVM segfault from custom MIR program #113360

Closed
cbeuw opened this issue Jul 5, 2023 · 2 comments
Closed

LLVM segfault from custom MIR program #113360

cbeuw opened this issue Jul 5, 2023 · 2 comments

Comments

@cbeuw
Copy link
Contributor

cbeuw commented Jul 5, 2023

#![feature(custom_mir, core_intrinsics)]
extern crate core;
use core::intrinsics::mir::*;

#[no_mangle]
#[custom_mir(dialect = "runtime", phase = "initial")]
pub fn fn11(
    mut _2: [i8; 7],
    mut _13: usize,
    mut _14: *mut (
        *mut u64,
        ((i64,), u8),
        [i64; 5],
        [i64; 5],
        *mut [bool; 1],
        [usize; 5],
    ),
) {
    mir! {
    let _23: Adt63;
    let _72: i16;
    let _93: ((*mut u64, ((i64,), u8), [i64; 5], [i64; 5], *mut [bool; 1], [usize; 5]), [bool; 8], u128, *mut [bool; 1]);
    let _118: Adt65;
    {
    Goto(bb1)
    }
    bb1 = {
    match (*_14).1.0.0 {
    42 => bb9,
    _ => bb111
    }
    }
    bb9 = {
    match (*_14).1.0.0 {
    2 => bb11,
    42 => bb16,
    _ => bb111
    }
    }
    bb11 = {
    (*_14).5[_13] = (-65452179397411209626475467761145739571_i128) as usize;
    match (*_14).1.0.0 {
    42 => bb9,
    _ => bb111
    }
    }
    bb16 = {
    _23.fld5 = core::ptr::addr_of_mut!(_23.fld0);
    match _23.fld4 {
    17412 => bb25,
    _ => bb11
    }
    }
    bb25 = {
    match _23.fld4 {
    17412 => bb31,
    _ => bb30
    }
    }
    bb30 = {
    match (*_14).1.0.0 {
    0 => bb1,
    _ => bb111
    }
    }
    bb31 = {
    match _23.fld4 {
    17412 => bb39,
    _ => bb111
    }
    }
    bb39 = {
    match _23.fld4 {
    17412 => bb42,
    _ => bb111
    }
    }
    bb42 = {
    _72 = _23.fld4;
    match _72 {
    0 => bb39,
    17412 => bb76,
    _ => bb30
    }
    }
    bb76 = {
    _14 = core::ptr::addr_of_mut!(_93.0);
    _118.fld2 = core::ptr::addr_of_mut!(_118.fld1);
    match _23.fld4 {
    0 => bb11,
    2 => bb30,
    _ => bb111
    }
    }
    bb111 = {
    Return()
    }

    }
}

pub fn main() {}
#[derive(Copy, Clone)]
pub struct Adt63 {
    fld0: i128,
    fld4: i16,
    fld5: *mut i128,
}
pub struct Adt65 {
    fld1: usize,
    fld2: *mut usize,
}
$ rustc -Copt-level=2 repro.rs 
/home/andy/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-9d2b497b46d0ef1c.so(+0x320a623)[0x7fc76060a623]
/lib64/libc.so.6(+0x3db70)[0x7fc75d0cfb70]
/home/andy/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libLLVM-16-rust-1.72.0-nightly.so(_ZN4llvm23ObjectSizeOffsetVisitor7computeEPNS_5ValueE+0x1f)[0x7fc759da829f]
/home/andy/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libLLVM-16-rust-1.72.0-nightly.so(_ZN4llvm23ObjectSizeOffsetVisitor12visitPHINodeERNS_7PHINodeE+0x4d)[0x7fc759da7f59]
/home/andy/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libLLVM-16-rust-1.72.0-nightly.so(_ZN4llvm23ObjectSizeOffsetVisitor7computeEPNS_5ValueE+0x2142)[0x7fc759daa3c2]
/home/andy/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libLLVM-16-rust-1.72.0-nightly.so(_ZN4llvm23ObjectSizeOffsetVisitor12visitPHINodeERNS_7PHINodeE+0xf6)[0x7fc759da8002]
/home/andy/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libLLVM-16-rust-1.72.0-nightly.so(_ZN4llvm23ObjectSizeOffsetVisitor7computeEPNS_5ValueE+0x2142)[0x7fc759daa3c2]
/home/andy/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libLLVM-16-rust-1.72.0-nightly.so(_ZN4llvm23ObjectSizeOffsetVisitor12visitPHINodeERNS_7PHINodeE+0xf6)[0x7fc759da8002]
/home/andy/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libLLVM-16-rust-1.72.0-nightly.so(_ZN4llvm23ObjectSizeOffsetVisitor7computeEPNS_5ValueE+0x2142)[0x7fc759daa3c2]
/home/andy/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libLLVM-16-rust-1.72.0-nightly.so(_ZN4llvm23ObjectSizeOffsetVisitor12visitPHINodeERNS_7PHINodeE+0x4d)[0x7fc759da7f59]
/home/andy/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libLLVM-16-rust-1.72.0-nightly.so(_ZN4llvm23ObjectSizeOffsetVisitor7computeEPNS_5ValueE+0x2142)[0x7fc759daa3c2]
/home/andy/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libLLVM-16-rust-1.72.0-nightly.so(_ZN4llvm13getObjectSizeEPKNS_5ValueERmRKNS_10DataLayoutEPKNS_17TargetLibraryInfoENS_14ObjectSizeOptsE+0x3e)[0x7fc759da817e]
/home/andy/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libLLVM-16-rust-1.72.0-nightly.so(_ZN4llvm13BasicAAResult5aliasERKNS_14MemoryLocationES3_RNS_11AAQueryInfoEPKNS_11InstructionE+0x3468)[0x7fc759a650ae]
/home/andy/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libLLVM-16-rust-1.72.0-nightly.so(_ZN4llvm9AAResults13getModRefInfoEPKNS_11InstructionERKSt8optionalINS_14MemoryLocationEERNS_11AAQueryInfoE+0x2ebd)[0x7fc759a41555]
/home/andy/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libLLVM-16-rust-1.72.0-nightly.so(+0x5a3e34c)[0x7fc759a3e34c]
/home/andy/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libLLVM-16-rust-1.72.0-nightly.so(_ZN4llvm25findAvailablePtrLoadStoreERKNS_14MemoryLocationEPNS_4TypeEbPNS_10BasicBlockERNS_14ilist_iteratorINS_12ilist_detail12node_optionsINS_11InstructionELb0ELb0EvEELb0ELb0EEEjPNS_9AAResultsEPbPj+0x5cc)[0x7fc759e43260]
/home/andy/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libLLVM-16-rust-1.72.0-nightly.so(_ZN4llvm17JumpThreadingPass30simplifyPartiallyRedundantLoadEPNS_8LoadInstE+0x163)[0x7fc759e41aa3]
/home/andy/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libLLVM-16-rust-1.72.0-nightly.so(_ZN4llvm17JumpThreadingPass7runImplERNS_8FunctionEPNS_17TargetLibraryInfoEPNS_19TargetTransformInfoEPNS_13LazyValueInfoEPNS_9AAResultsEPNS_14DomTreeUpdaterEbSt10unique_ptrINS_18BlockFrequencyInfoESt14default_deleteISE_EESD_INS_21BranchProbabilityInfoESF_ISI_EE+0xbb6)[0x7fc759cf57b6]
/home/andy/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libLLVM-16-rust-1.72.0-nightly.so(_ZN4llvm17JumpThreadingPass3runERNS_8FunctionERNS_15AnalysisManagerIS1_JEEE+0x186)[0x7fc759cf4198]
/home/andy/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libLLVM-16-rust-1.72.0-nightly.so(+0x5cf400d)[0x7fc759cf400d]
/home/andy/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libLLVM-16-rust-1.72.0-nightly.so(_ZN4llvm11PassManagerINS_8FunctionENS_15AnalysisManagerIS1_JEEEJEE3runERS1_RS3_+0xf7a)[0x7fc759f3dc3a]
/home/andy/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libLLVM-16-rust-1.72.0-nightly.so(_ZN4llvm26CGSCCToFunctionPassAdaptor3runERNS_13LazyCallGraph3SCCERNS_15AnalysisManagerIS2_JRS1_EEES5_RNS_17CGSCCUpdateResultE+0x3a5)[0x7fc759f413c3]
/home/andy/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libLLVM-16-rust-1.72.0-nightly.so(+0x5f41019)[0x7fc759f41019]
/home/andy/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libLLVM-16-rust-1.72.0-nightly.so(_ZN4llvm11PassManagerINS_13LazyCallGraph3SCCENS_15AnalysisManagerIS2_JRS1_EEEJS4_RNS_17CGSCCUpdateResultEEE3runERS2_RS5_S4_S7_+0x582)[0x7fc75a00fdd4]
/home/andy/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libLLVM-16-rust-1.72.0-nightly.so(_ZN4llvm21DevirtSCCRepeatedPass3runERNS_13LazyCallGraph3SCCERNS_15AnalysisManagerIS2_JRS1_EEES5_RNS_17CGSCCUpdateResultE+0x188)[0x7fc75a00eb8e]
/home/andy/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libLLVM-16-rust-1.72.0-nightly.so(_ZN4llvm33ModuleToPostOrderCGSCCPassAdaptor3runERNS_6ModuleERNS_15AnalysisManagerIS1_JEEE+0xb88)[0x7fc759e10a08]
/home/andy/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libLLVM-16-rust-1.72.0-nightly.so(+0x5e0fe6d)[0x7fc759e0fe6d]
/home/andy/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libLLVM-16-rust-1.72.0-nightly.so(_ZN4llvm11PassManagerINS_6ModuleENS_15AnalysisManagerIS1_JEEEJEE3runERS1_RS3_+0xcf)[0x7fc759f42113]
/home/andy/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libLLVM-16-rust-1.72.0-nightly.so(_ZN4llvm24ModuleInlinerWrapperPass3runERNS_6ModuleERNS_15AnalysisManagerIS1_JEEE+0x1ab)[0x7fc759f3aaeb]
/home/andy/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libLLVM-16-rust-1.72.0-nightly.so(+0x5f3a92d)[0x7fc759f3a92d]
/home/andy/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libLLVM-16-rust-1.72.0-nightly.so(_ZN4llvm11PassManagerINS_6ModuleENS_15AnalysisManagerIS1_JEEEJEE3runERS1_RS3_+0xcf)[0x7fc759f42113]
/home/andy/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-9d2b497b46d0ef1c.so(+0x293a289)[0x7fc75fd3a289]
/home/andy/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-9d2b497b46d0ef1c.so(+0x2936e7e)[0x7fc75fd36e7e]
/home/andy/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-9d2b497b46d0ef1c.so(+0x2936934)[0x7fc75fd36934]
/home/andy/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-9d2b497b46d0ef1c.so(+0x26f7f28)[0x7fc75faf7f28]
/home/andy/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-9d2b497b46d0ef1c.so(+0x26f5d89)[0x7fc75faf5d89]
/home/andy/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-9d2b497b46d0ef1c.so(+0x2704d76)[0x7fc75fb04d76]
/home/andy/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libstd-c1ef87628285f700.so(rust_metadata_std_546c48fd97b1d9d5+0x105695)[0x7fc75d375695]
/lib64/libc.so.6(+0x8c907)[0x7fc75d11e907]
/lib64/libc.so.6(+0x112870)[0x7fc75d1a4870]
Segmentation fault (core dumped)

Does not trigger any debug assertion failures in LLVM when compiled with them enabled.

I couldn't get a standalone .ll reproducer as -Cno-prepopulate-passes makes the bug go away.

Not related to target-illegal vectors as nightly-2023-05-25 still segfaults.

As the backtrace suggests, the segfault is likely from JumpThreadingPass. -opt-bisect-limit prevents the segfault if this is not run.

cc @nikic

@nikic
Copy link
Contributor

nikic commented Jul 5, 2023

This looks like the same issue as llvm/llvm-project#63013.

@cbeuw
Copy link
Contributor Author

cbeuw commented Jul 5, 2023

Ah yes indeed. I thought the fix was in Rust's LLVM branch, but it isn't. I'll keep my local rustc patched.

@cbeuw cbeuw closed this as not planned Won't fix, can't repro, duplicate, stale Jul 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants