Issue 235301
Summary [NewGVN] EH funclet token replaced with poison: "cleanupret from %cl" becomes "cleanupret from poison" on unreachable cleanup blocks -> verifier abort (Broken module)
Labels new issue
Assignees
Reporter leidian977
    ## Summary

NewGVN replaces the `CleanupPadInst` token operand of a `cleanupret`
with `poison`, producing `cleanupret from poison` — invalid IR
(`cleanupret` requires a pad operand). The verifier then rejects the
module: `LLVM ERROR: Broken module found, compilation aborted!`. The
input module is valid on its own (`opt -passes=verify` passes); only
NewGVN breaks it.

## Reduced test case (llvm-reduce'd, 12 lines)

    target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
    target triple = "x86_64-pc-windows-msvc18.0"

    define void @test1() personality ptr null {
    bb:
      unreachable

    unreachable:            ; No predecessors!
      %cl = cleanuppad within none []
      cleanupret from %cl unwind to caller
    }

## Reproduction

    $ opt -S -passes=newgvn f4.ll -o /dev/null
    CleanupReturnInst needs to be provided a CleanupPad
      cleanupret from poison unwind to caller
    token poison
    LLVM ERROR: Broken module found, compilation aborted!
    PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ ...
    Aborted (core dumped)
    [exit code 134 / SIGABRT]

    $ opt -S -passes=verify f4.ll -o /dev/null; echo $?
    0        ; input module is valid on its own

## Root cause

`llvm/lib/Transforms/Scalar/NewGVN.cpp`: the poison-simplification path
treats `CleanupPadInst` as an ordinary simplifiable value and lets an
unreachable-block simplification rewrite the `cleanupret` pad operand
to `poison`. `git log --grep=cleanuppad --since=2024-06` shows 11
commits, none touching NewGVN — the GVN side of this EH family is
unexplored (the coro side has #234569 / #226735 open).

## Impact

Any Windows funclet IR containing unreachable cleanup/catch blocks
(C++/SEH pipelines, pre-LTO pruning output, coro-split residue) aborts
when run through NewGVN/GVN. User-visible as "compiler refuses to
compile valid code".

## Suggested fix

Exclude `CleanupPadInst` / `CatchPadInst` (token-type instructions)
from NewGVN's replaceable value set, or at least skip funclet-boundary
operand replacement in unreachable blocks.

## Environment

- LLVM `24.0.0git`, built from git HEAD `cc2acc33a5b`
- Reproduced with `opt -S -passes=newgvn` and `opt -S -passes=verify`
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to