Skip to content

Recursive function calls using multi-threading triggers assertion #129

@stlemme

Description

@stlemme
//minified repro sample
fn rec_func_wrapper(n: i32) -> i32 {
	// an @ for rec_func() does not trigger the assertion, but causes full unrolling of the recursion
	fn rec_func(x: i32) -> i32 {
		if x == 0 {
			1
		} else {
			let buffer = alloc_cpu(sizeof[i32]());
			let data = buffer.data as &mut [i32];

			// removing the threading logic and computing rec_func(x-1) directly does not show the issue
			let task = spawn(|| {
				data(0) = rec_func(x-1);
			});

			let tid = task();

			sync(tid);

			let result = data(0);
			release(buffer);

			if result > 0 { 1 } else { 0 }
		}
	}

	rec_func(n)
}


#[export]
fn main() -> i32 {
	let t = rec_func_wrapper(5);

	if t > 0 { 0 } else { -1 }
}

triggers Assertion failed: odef->op(i) != odef, file D:\Projects\anydsl\thorin\src\thorin\transform\importer.cpp, line 80

and in previous versions of thorin this ended up with a stack overflow.

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