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

suspensions inside for loops generate invalid LLVM IR #3076

Closed
andrewrk opened this issue Aug 16, 2019 · 0 comments
Closed

suspensions inside for loops generate invalid LLVM IR #3076

andrewrk opened this issue Aug 16, 2019 · 0 comments
Labels
bug Observed behavior contradicts documented or intended behavior
Milestone

Comments

@andrewrk
Copy link
Member

andrewrk commented Aug 16, 2019

const std = @import("std");
const expect = std.testing.expect;

var global_frame: ?anyframe = null;

test "suspend in for loop" {
    _ = async atest();
    while (global_frame) |f| resume f;
}

fn atest() void {
    expect(func([_]u8{ 1, 2, 3 }) == 6);
}
fn func(stuff: []const u8) u32 {
    global_frame = @frame();
    var sum: u32 = 0;
    for (stuff) |x| {
        suspend;
        sum += x;
    }
    global_frame = null;
    return sum;
}

Expected to pass. Instead:

Instruction does not dominate all uses!
  %8 = load i64, i64* %7, align 8, !dbg !1349
  %10 = icmp ult i64 %9, %8, !dbg !1349
Instruction does not dominate all uses!
  %13 = getelementptr inbounds i8, i8* %12, i64 %9, !dbg !1349
  %17 = load i8, i8* %13, align 1, !dbg !1356
Instruction does not dominate all uses!
  %9 = load i64, i64* %i, align 8, !dbg !1349
  %22 = add nuw i64 %9, 1, !dbg !1349
LLVM ERROR: Broken module found, compilation aborted!

The implementation needs to spill some more values here to make this work.

@andrewrk andrewrk added the bug Observed behavior contradicts documented or intended behavior label Aug 16, 2019
@andrewrk andrewrk added this to the 0.5.0 milestone Aug 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior
Projects
None yet
Development

No branches or pull requests

1 participant