llvm / llvm/llvm-project

[llvm-reduce] operands-to-args crashes on a landingpad catch clause

Open Beginner friendly
#219,667 2 comments 0 reactions 0 assignees View on GitHub
llvm-reduce tools:llvm-reduce
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

## Summary

`llvm-reduce --delta-passes=operands-to-args` aborts when it selects a
landing-pad catch-clause constant for replacement. The pass attempts to
replace that constant with a function argument, violating the
constant-clause invariant.

This reproduces with an assertions-enabled LLVM 24.0.0git build at revision
`2e3d50b4111f324fb615c3c18d02189caa1ef62d` in both single-threaded and
parallel executions.

## Reproducer

save the following content to a reduced.ll file:
```llvm
@T = external constant ptr

declare void @g()
declare i32 @p(...)

define void @f() personality ptr @p {
entry:
invoke void @g() to label %return unwind label %lpad

lpad:
%x = landingpad { ptr, i32 }
catch ptr @T
unreachable

return:
ret void
}
```

Run:

```sh
llvm-reduce --preserve-debug-environment -j 1 \
--delta-passes=operands-to-args \
--test /bin/true reduced.ll
```

The input is accepted by both `llvm-as` and `opt -passes=verify`.

## Actual behavior

`llvm-reduce` exits 134 with:

```text
llvm/Support/Casting.h:560: Assertion `isa(Val) &&
"cast() argument of incompatible type!"' failed.
```

The assertion instantiation is `To = Constant; From = Use`.

The relevant symbolized frames are:

```text
Verifier::visitLandingPadInst
llvm::verifyModule
llvm::ReducerWorkItem::verify
CheckChunk
llvm::runDeltaPass
```

The crash reproduces in three out of three runs with `-j 1` and three out of
three runs with `-j 24`. A cleanup-only landing pad with no clause operand
completes normally under the same delta pass.

## Possible Cause

`ReduceOperandsToArgs.cpp::canReduceUse` does not exclude operands of a
`LandingPadInst`. The pass substitutes the catch clause with a newly created
function argument. Landing-pad clauses must be constants, and
`LandingPadInst::getClause()` enforces that invariant with `cast`.
The reducer's candidate verifier reaches the assertion while checking the
transformed module.

## Expected behavior

`operands-to-args` should skip landing-pad clause operands, preserving the
required constant operand invariant.

Contributor guide

Open the contributing guide

Research direction

Start in ReduceOperandsToArgs.cpp at canReduceUse and compare its operand handling with LandingPadInst::getClause(). Run the provided reduced.ll reproducer with llvm-reduce and verify that operands-to-args no longer aborts for a landing-pad catch clause, while the input remains accepted by llvm-as and opt -passes=verify.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers, tooling
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
88/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.