AnyDSL / thorin

The Higher-Order Intermediate Representation

Home Page:https://anydsl.github.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

michael-kenzel opened this issue · comments

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.

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;
}