Skip to content
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

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

Merged
merged 3 commits into from
Nov 29, 2023

Conversation

fpetrogalli
Copy link
Member

@fpetrogalli fpetrogalli commented Nov 23, 2023

The script is based on an example provided by Tim
Northover (https://github.com/TNorthover).

@llvmbot
Copy link
Collaborator

llvmbot commented Nov 23, 2023

@llvm/pr-subscribers-llvm-binary-utilities

Author: Francesco Petrogalli (fpetrogalli)

Changes

The script is based on an exmaple provided by Tim
Northover (https://github.com/TNorthover).


Full diff: https://github.com/llvm/llvm-project/pull/73237.diff

1 Files Affected:

  • (modified) llvm/docs/CommandGuide/llvm-reduce.rst (+29)
diff --git a/llvm/docs/CommandGuide/llvm-reduce.rst b/llvm/docs/CommandGuide/llvm-reduce.rst
index cd49ceba2d6b6e8..b03784696d55786 100644
--- a/llvm/docs/CommandGuide/llvm-reduce.rst
+++ b/llvm/docs/CommandGuide/llvm-reduce.rst
@@ -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
+-------
 
+`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 -S $1 -o /dev/null \
+     |& 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`.

The script is based on an example provided by Tim
Northover (https://github.com/TNorthover).
llvm/docs/CommandGuide/llvm-reduce.rst Outdated Show resolved Hide resolved
1. Disable output of opt instead of dumping output to /dev/null
2. Do not specify -S
@fpetrogalli fpetrogalli merged commit 792253a into llvm:main Nov 29, 2023
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants