Issue 241473
Summary [DSE] `cast<Constant>` assertion on `llvm.coro.end` with a non-constant `i1` operand
Labels new issue
Assignees
Reporter arie2026
    Since #238017, the `DSEState` constructor calls `AnyCoroEndInst::isFallthrough()` on every `llvm.coro.end` /
`llvm.coro.end.async` call. `isUnwind()` does `cast<Constant>(getArgOperand(1))`, but that operand has no
`ImmArg` and the verifier accepts any `i1`. So DSE now crashes on any function with such a call, even one without
stores and outside a coroutine.

Reproducer (`opt -passes=dse`, no target flags; also reproduces on 5e457cda8d5a and f2808fc79):
```llvm
define void @f(i1 %c) {
  call void @llvm.coro.end(ptr null, i1 %c, token none)
  ret void
}
declare void @llvm.coro.end(ptr, i1, token)
```

```
$ opt -passes=dse -disable-output test.ll
opt: llvm/include/llvm/Support/Casting.h:572: decltype(auto) llvm::cast(From *) [To = llvm::Constant, From = llvm::Value]: Assertion `isa<To>(Val) && "cast<Ty>() argument of incompatible type!"' failed.
2.      Running pass "dse" on function "f"
#11 eliminateDeadStores(...)            ; DSEState ctor / AnyCoroEndInst::isUnwind() inlined
#12 llvm::DSEPass::run(...)
#13 llvm::detail::PassModel<llvm::Function, llvm::DSEPass, ...>::runImpl(...)
#14 llvm::PassManager<llvm::Function, ...>::run(...)
#16 llvm::ModuleToFunctionPassAdaptor::run(...)
#18 llvm::PassManager<llvm::Module, ...>::run(...)
#19 llvm::runPassPipeline(...)
#20 optMain
```

`call void (ptr, i1, ...) @llvm.coro.end.async(ptr null, i1 %c)` crashes the same way. `i1 true/false/poison/undef` do not.

Expected: no crash. Either DSE treats an unknown flag conservatively (e.g. `dyn_cast<ConstantInt>` and add the block
as a root unless it is `true`), or the operand is marked `ImmArg` so the verifier rejects this IR.

Notes: regression from f6a1d4d7b459 (#238017, 2026-11-03), which added the `isFallthrough()` call in `DSEState`.
Frontends always emit a constant here, so this needs hand-written or fuzzed IR. cc @cofibrant

Found with a mutation-based IR fuzzer. Triage, test-case minimization and parts of this write-up were
assisted by an LLM; verified the reproducer on 9dce18f0e.

Assisted-by: Claude (Anthropic)
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to