Skip to content

[llvm][docs] Add example use of llvm-reduce. #73237

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

Merged
merged 3 commits into from
Nov 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions llvm/docs/CommandGuide/llvm-reduce.rst
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,33 @@ EXIT STATUS
:program:`llvm-reduce` returns 0 under normal operation. It returns a non-zero
exit code if there were any errors.

EXAMPLE
-------

:program:`llvm-reduce` can be used to simplify a test that causes a
compiler crash.

For example, let's assume that `opt` is crashing on the IR file
`test.ll` with error message `Assertion failed at line 1234 of
WhateverFile.cpp`, when running at `-O2`.

The test case of `test.ll` can be reduced by invoking the following
command:

.. code-block:: bash

$(LLVM_BUILD_FOLDER)/bin/llvm-reduce --test=script.sh <path to>/test.ll

The shell script passed to the option `test` consists of the
following:

.. code-block:: bash

$(LLVM_BUILD_FOLDER)/bin/opt -O2 -disable-output $1 \
|& grep "Assertion failed at line 1234 of WhateverFile.cpp"

(In this script, `grep` exits with 0 if it finds the string and that
becomes the whole script's status.)

This example can be generalized to other tools that process IR files,
for example `llc`.