50 lines · plain
1; Tests the never-silent floor for a dynamically sized alloca (a VLA) that is2; genuinely live across a suspend point. Such an alloca cannot be materialized3; as a fixed coroutine-frame field (its size is only known at run time, after4; the frame layout is fixed at coro.begin). CoroSplit must fail loudly here5; rather than dereferencing the empty std::optional returned by6; getAllocationSize() and crashing (SIGSEGV) inside frame construction.7;8; reuse-storage selects OptimizeFrame, matching clang at -O2.9;10; RUN: not --crash opt < %s -passes='cgscc(coro-split<reuse-storage>)' -S 2>&1 | FileCheck %s11 12; CHECK: dynamically sized alloca that is live across a suspend point13 14define ptr @f(i32 %n) presplitcoroutine {15entry:16 %id = call token @llvm.coro.id(i32 0, ptr null, ptr null, ptr null)17 %size = call i32 @llvm.coro.size.i32()18 %alloc = call ptr @malloc(i32 %size)19 %hdl = call ptr @llvm.coro.begin(token %id, ptr %alloc)20 ; A dynamically sized alloca that is written before the suspend and read after21 ; it, so it is genuinely live across the suspend point.22 %vla = alloca i8, i32 %n, align 1623 call void @use(ptr %vla)24 %sp = call i8 @llvm.coro.suspend(token none, i1 false)25 switch i8 %sp, label %suspend [i8 0, label %resume26 i8 1, label %cleanup]27resume:28 call void @use(ptr %vla)29 br label %cleanup30 31cleanup:32 %mem = call ptr @llvm.coro.free(token %id, ptr %hdl)33 call void @free(ptr %mem)34 br label %suspend35 36suspend:37 call void @llvm.coro.end(ptr %hdl, i1 0, token none)38 ret ptr %hdl39}40 41declare token @llvm.coro.id(i32, ptr, ptr, ptr)42declare i32 @llvm.coro.size.i32()43declare ptr @llvm.coro.begin(token, ptr)44declare i8 @llvm.coro.suspend(token, i1)45declare ptr @llvm.coro.free(token, ptr)46declare void @llvm.coro.end(ptr, i1, token)47declare ptr @malloc(i32)48declare void @free(ptr)49declare void @use(ptr)50