AnyDSL / thorin

The Higher-Order Intermediate Representation
https://anydsl.github.io
GNU Lesser General Public License v3.0
151 stars 15 forks source link

assigning/initializing pointer to member of struct accessed through mutable pointer triggers assertion #130

Open michael-kenzel opened 1 year ago

michael-kenzel commented 1 year ago

the following code will reproduce the issue:

struct Req {}

struct X {
    _: u32,
    req: Req
}

fn test(x: &mut X) {
    let mut p = x;
    let r = &mut p.req;
}

triggers

thorin/src/thorin/primop.cpp:80: thorin::LEA::LEA(const thorin::Def*, const thorin::Def*, thorin::Debug): Assertion `false && "unreachable"' failed.
stlemme commented 1 year ago

Modifying the sample to let r = &mut (*p).req; will avoid the assertion. But this leads to the follow up problem in:

fn test(x: &mut X) {
    let mut p:&mut X = x;
    // let mut r = &mut p.req;
    let mut r = &mut (*p).req;
    // this triggers Assertion failed: (!r || dynamic_cast<L*>(r)) && "cast not possible", file D:\Projects\anydsl\thorin\src\thorin/util/cast.h, line 42
    // r.val = 3;
    // this will properly update req in x
    (*r).val = 3;
}