Skip to content

Commit 792253a

Browse files
authored
[llvm][docs] Add example use of llvm-reduce. (#73237)
The script is based on an example provided by Tim Northover (https://github.com/TNorthover).
1 parent 771e9cd commit 792253a

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

llvm/docs/CommandGuide/llvm-reduce.rst

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,33 @@ EXIT STATUS
105105
:program:`llvm-reduce` returns 0 under normal operation. It returns a non-zero
106106
exit code if there were any errors.
107107

108+
EXAMPLE
109+
-------
108110

111+
:program:`llvm-reduce` can be used to simplify a test that causes a
112+
compiler crash.
113+
114+
For example, let's assume that `opt` is crashing on the IR file
115+
`test.ll` with error message `Assertion failed at line 1234 of
116+
WhateverFile.cpp`, when running at `-O2`.
117+
118+
The test case of `test.ll` can be reduced by invoking the following
119+
command:
120+
121+
.. code-block:: bash
122+
123+
$(LLVM_BUILD_FOLDER)/bin/llvm-reduce --test=script.sh <path to>/test.ll
124+
125+
The shell script passed to the option `test` consists of the
126+
following:
127+
128+
.. code-block:: bash
129+
130+
$(LLVM_BUILD_FOLDER)/bin/opt -O2 -disable-output $1 \
131+
|& grep "Assertion failed at line 1234 of WhateverFile.cpp"
132+
133+
(In this script, `grep` exits with 0 if it finds the string and that
134+
becomes the whole script's status.)
135+
136+
This example can be generalized to other tools that process IR files,
137+
for example `llc`.

0 commit comments

Comments
 (0)