irsmith 0.2.0__tar.gz → 0.3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {irsmith-0.2.0 → irsmith-0.3.0}/LICENSE-MIT +1 -1
- {irsmith-0.2.0 → irsmith-0.3.0}/PKG-INFO +19 -5
- {irsmith-0.2.0 → irsmith-0.3.0}/README.md +17 -3
- {irsmith-0.2.0 → irsmith-0.3.0}/pyproject.toml +4 -3
- {irsmith-0.2.0 → irsmith-0.3.0}/server.json +2 -2
- irsmith-0.3.0/src/irsmith/clang/crash.py +175 -0
- irsmith-0.3.0/src/irsmith/clang/script.py +138 -0
- {irsmith-0.2.0 → irsmith-0.3.0}/src/irsmith/config.py +2 -2
- {irsmith-0.2.0 → irsmith-0.3.0}/src/irsmith/models.py +29 -0
- {irsmith-0.2.0 → irsmith-0.3.0}/src/irsmith/pipeline/run.py +17 -7
- {irsmith-0.2.0 → irsmith-0.3.0}/src/irsmith/reduce/driver.py +25 -5
- {irsmith-0.2.0 → irsmith-0.3.0}/src/irsmith/server.py +36 -3
- {irsmith-0.2.0 → irsmith-0.3.0}/src/irsmith/signature/parse.py +2 -1
- irsmith-0.3.0/tests/fakes/fake_clang.py +45 -0
- irsmith-0.3.0/tests/fakes/fake_cvise.py +38 -0
- irsmith-0.3.0/tests/fixtures/clang/apple.stderr +19 -0
- irsmith-0.3.0/tests/fixtures/clang/bug-3f9a1c.cpp +3 -0
- irsmith-0.3.0/tests/fixtures/clang/bug-3f9a1c.sh +4 -0
- irsmith-0.3.0/tests/fixtures/clang/fatal-9c0e2d.c +6 -0
- irsmith-0.3.0/tests/fixtures/clang/fatal-9c0e2d.sh +4 -0
- irsmith-0.3.0/tests/fixtures/clang/upstream.stderr +23 -0
- irsmith-0.3.0/tests/integration/test_clang_crash.py +106 -0
- {irsmith-0.2.0 → irsmith-0.3.0}/tests/integration/test_stdio.py +24 -1
- irsmith-0.3.0/tests/unit/__init__.py +0 -0
- irsmith-0.3.0/tests/unit/test_clang.py +188 -0
- {irsmith-0.2.0 → irsmith-0.3.0}/tests/unit/test_signature.py +3 -0
- {irsmith-0.2.0 → irsmith-0.3.0}/uv.lock +1 -1
- {irsmith-0.2.0 → irsmith-0.3.0}/.github/workflows/release.yml +0 -0
- {irsmith-0.2.0 → irsmith-0.3.0}/.github/workflows/test.yml +0 -0
- {irsmith-0.2.0 → irsmith-0.3.0}/.gitignore +0 -0
- {irsmith-0.2.0 → irsmith-0.3.0}/.python-version +0 -0
- {irsmith-0.2.0 → irsmith-0.3.0}/LICENSE-APACHE +0 -0
- {irsmith-0.2.0 → irsmith-0.3.0}/demo/README.md +0 -0
- {irsmith-0.2.0 → irsmith-0.3.0}/demo/pr248279.ll +0 -0
- {irsmith-0.2.0 → irsmith-0.3.0}/demo/run_demo.py +0 -0
- {irsmith-0.2.0 → irsmith-0.3.0}/docs/clients.md +0 -0
- {irsmith-0.2.0 → irsmith-0.3.0}/src/irsmith/__init__.py +0 -0
- {irsmith-0.2.0 → irsmith-0.3.0}/src/irsmith/__main__.py +0 -0
- {irsmith-0.2.0 → irsmith-0.3.0}/src/irsmith/app.py +0 -0
- {irsmith-0.2.0 → irsmith-0.3.0}/src/irsmith/bisect/__init__.py +0 -0
- {irsmith-0.2.0 → irsmith-0.3.0}/src/irsmith/bisect/driver.py +0 -0
- {irsmith-0.2.0 → irsmith-0.3.0}/src/irsmith/bisect/git.py +0 -0
- {irsmith-0.2.0/src/irsmith/oracle → irsmith-0.3.0/src/irsmith/clang}/__init__.py +0 -0
- {irsmith-0.2.0 → irsmith-0.3.0}/src/irsmith/errors.py +0 -0
- {irsmith-0.2.0 → irsmith-0.3.0}/src/irsmith/jobs.py +0 -0
- {irsmith-0.2.0 → irsmith-0.3.0}/src/irsmith/limits_exec.py +0 -0
- {irsmith-0.2.0/src/irsmith/pipeline → irsmith-0.3.0/src/irsmith/oracle}/__init__.py +0 -0
- {irsmith-0.2.0 → irsmith-0.3.0}/src/irsmith/oracle/check.py +0 -0
- {irsmith-0.2.0 → irsmith-0.3.0}/src/irsmith/oracle/spec.py +0 -0
- {irsmith-0.2.0/src/irsmith/triage → irsmith-0.3.0/src/irsmith/pipeline}/__init__.py +0 -0
- {irsmith-0.2.0 → irsmith-0.3.0}/src/irsmith/pipeline/diff.py +0 -0
- {irsmith-0.2.0 → irsmith-0.3.0}/src/irsmith/pipeline/dumps.py +0 -0
- {irsmith-0.2.0 → irsmith-0.3.0}/src/irsmith/pipeline/passes.py +0 -0
- {irsmith-0.2.0 → irsmith-0.3.0}/src/irsmith/proc.py +0 -0
- {irsmith-0.2.0 → irsmith-0.3.0}/src/irsmith/py.typed +0 -0
- {irsmith-0.2.0 → irsmith-0.3.0}/src/irsmith/reduce/__init__.py +0 -0
- {irsmith-0.2.0 → irsmith-0.3.0}/src/irsmith/signature/__init__.py +0 -0
- {irsmith-0.2.0 → irsmith-0.3.0}/src/irsmith/signature/normalize.py +0 -0
- {irsmith-0.2.0 → irsmith-0.3.0}/src/irsmith/signature/report.py +0 -0
- {irsmith-0.2.0 → irsmith-0.3.0}/src/irsmith/store.py +0 -0
- {irsmith-0.2.0/tests → irsmith-0.3.0/src/irsmith/triage}/__init__.py +0 -0
- {irsmith-0.2.0 → irsmith-0.3.0}/src/irsmith/triage/github.py +0 -0
- {irsmith-0.2.0 → irsmith-0.3.0}/src/irsmith/triage/search.py +0 -0
- {irsmith-0.2.0/tests/integration → irsmith-0.3.0/tests}/__init__.py +0 -0
- {irsmith-0.2.0 → irsmith-0.3.0}/tests/conftest.py +0 -0
- {irsmith-0.2.0 → irsmith-0.3.0}/tests/fakes/fake_gh.py +0 -0
- {irsmith-0.2.0 → irsmith-0.3.0}/tests/fakes/fake_llvm_reduce.py +0 -0
- {irsmith-0.2.0 → irsmith-0.3.0}/tests/fakes/fake_ninja.py +0 -0
- {irsmith-0.2.0 → irsmith-0.3.0}/tests/fakes/fake_opt.py +0 -0
- {irsmith-0.2.0 → irsmith-0.3.0}/tests/fixtures/bad.ll +0 -0
- {irsmith-0.2.0 → irsmith-0.3.0}/tests/fixtures/bad.mlir +0 -0
- {irsmith-0.2.0 → irsmith-0.3.0}/tests/fixtures/bad_verify.mlir +0 -0
- {irsmith-0.2.0 → irsmith-0.3.0}/tests/fixtures/github/api_frame.json +0 -0
- {irsmith-0.2.0 → irsmith-0.3.0}/tests/fixtures/github/api_message.json +0 -0
- {irsmith-0.2.0 → irsmith-0.3.0}/tests/fixtures/github/api_pass.json +0 -0
- {irsmith-0.2.0 → irsmith-0.3.0}/tests/fixtures/github/gh_message.json +0 -0
- {irsmith-0.2.0 → irsmith-0.3.0}/tests/fixtures/github/gh_pass.json +0 -0
- {irsmith-0.2.0 → irsmith-0.3.0}/tests/fixtures/many_functions.ll +0 -0
- {irsmith-0.2.0 → irsmith-0.3.0}/tests/fixtures/print_changed.txt +0 -0
- {irsmith-0.2.0 → irsmith-0.3.0}/tests/fixtures/small.ll +0 -0
- {irsmith-0.2.0 → irsmith-0.3.0}/tests/fixtures/stderr/darwin_lcssa_nested_pipeline.txt +0 -0
- {irsmith-0.2.0 → irsmith-0.3.0}/tests/fixtures/stderr/darwin_trigger_crash.txt +0 -0
- {irsmith-0.2.0 → irsmith-0.3.0}/tests/fixtures/stderr/darwin_verifier_error.txt +0 -0
- {irsmith-0.2.0 → irsmith-0.3.0}/tests/fixtures/stderr/fake_darwin.txt +0 -0
- {irsmith-0.2.0 → irsmith-0.3.0}/tests/fixtures/stderr/fake_glibc.txt +0 -0
- {irsmith-0.2.0 → irsmith-0.3.0}/tests/fixtures/stderr/fake_mlir.txt +0 -0
- {irsmith-0.2.0 → irsmith-0.3.0}/tests/fixtures/stderr/mlir_diagnostic.txt +0 -0
- {irsmith-0.2.0 → irsmith-0.3.0}/tests/fixtures/stderr/mlir_op_verifier.txt +0 -0
- {irsmith-0.2.0 → irsmith-0.3.0}/tests/fixtures/stderr/parse_error.txt +0 -0
- {irsmith-0.2.0 → irsmith-0.3.0}/tests/fixtures/two_functions.ll +0 -0
- {irsmith-0.2.0/tests/unit → irsmith-0.3.0/tests/integration}/__init__.py +0 -0
- {irsmith-0.2.0 → irsmith-0.3.0}/tests/integration/test_real_tools.py +0 -0
- {irsmith-0.2.0 → irsmith-0.3.0}/tests/unit/test_bisect.py +0 -0
- {irsmith-0.2.0 → irsmith-0.3.0}/tests/unit/test_config.py +0 -0
- {irsmith-0.2.0 → irsmith-0.3.0}/tests/unit/test_oracle.py +0 -0
- {irsmith-0.2.0 → irsmith-0.3.0}/tests/unit/test_proc.py +0 -0
- {irsmith-0.2.0 → irsmith-0.3.0}/tests/unit/test_reduce.py +0 -0
- {irsmith-0.2.0 → irsmith-0.3.0}/tests/unit/test_store.py +0 -0
- {irsmith-0.2.0 → irsmith-0.3.0}/tests/unit/test_tools.py +0 -0
- {irsmith-0.2.0 → irsmith-0.3.0}/tests/unit/test_triage.py +0 -0
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: irsmith
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.0
|
|
4
4
|
Summary: MCP server that helps coding agents debug LLVM, MLIR and CIRCT crashes and pass pipelines
|
|
5
5
|
Project-URL: Homepage, https://github.com/ambujone/irsmith
|
|
6
6
|
Project-URL: Issues, https://github.com/ambujone/irsmith/issues
|
|
7
7
|
Project-URL: Source, https://github.com/ambujone/irsmith
|
|
8
|
-
Author-email: Ambuj
|
|
8
|
+
Author-email: "Ambuj A." <ambujone@gmail.com>
|
|
9
9
|
License-Expression: MIT OR Apache-2.0
|
|
10
10
|
License-File: LICENSE-APACHE
|
|
11
11
|
License-File: LICENSE-MIT
|
|
@@ -30,7 +30,7 @@ Description-Content-Type: text/markdown
|
|
|
30
30
|
|
|
31
31
|
# irsmith
|
|
32
32
|
|
|
33
|
-
irsmith is an MCP server that lets coding agents debug LLVM, MLIR and CIRCT tools using your own local builds. It runs a compiler command and reads the crash signature, shrinks a crashing input to a small reproducer, and shows which pass changed the IR and how.
|
|
33
|
+
irsmith is an MCP server that lets coding agents debug LLVM, MLIR and CIRCT tools using your own local builds. It runs a compiler command and reads the crash signature, shrinks a crashing input to a small reproducer, and shows which pass changed the IR and how. It can also start from the report that clang prints when it crashes.
|
|
34
34
|
|
|
35
35
|
<!-- mcp-name: io.github.ambujone/irsmith -->
|
|
36
36
|
|
|
@@ -82,12 +82,26 @@ Any MCP client that can launch a stdio server works the same way: the command is
|
|
|
82
82
|
| `diff_passes` | Runs a pipeline with `opt -print-changed`, or with `--mlir-print-ir-after-all --mlir-print-ir-after-change` for `mlir-opt` and `circt-opt`, and returns one diff hunk per pass that changed the IR, within a token budget. If the tool crashes partway, it returns the passes that finished and the crash signature. |
|
|
83
83
|
| `reduce` | Shrinks a crashing `.ll`, `.bc` or `.mir` file with llvm-reduce, or a `.mlir` file with circt-reduce. Each candidate must crash with the same signature as the original, so the reducer cannot drift to a different bug. Runs as a job. |
|
|
84
84
|
| `bisect` | Finds the commit that introduced a crash, or with `find: "fix"` the commit that fixed it. At each step it checks out the commit, runs `ninja -C <build> <targets>` in your build dir and runs the command. A failed build or an unclear result skips the commit. Runs as a job. |
|
|
85
|
+
| `from_clang_crash` | Starts from the run script that clang prints when it crashes. Reruns its `clang -cc1` command, returns the crash signature and whether the crash is in the frontend or in LLVM, and can reduce it. See [When clang crashes](https://github.com/ambujone/irsmith#when-clang-crashes). |
|
|
85
86
|
| `find_duplicates` | Searches GitHub issues for the same crash, given a signature id, a stderr handle or pasted text. Runs up to 3 searches (the assertion text, the top frame, the pass) and ranks the issues by how well they match. Uses `gh` when it is logged in, else the public API. Results are cached for 24 hours. |
|
|
86
87
|
| `job_status`, `job_cancel` | Follow or stop a `reduce` or `bisect` job. Calls wait at most 55 seconds, because many clients drop longer calls. |
|
|
87
88
|
| `read_artifact` | Reads part of a stored output (stderr, IR dumps, the reduced file) by handle, with offset, limit and grep. |
|
|
88
89
|
|
|
89
90
|
Commands are argv arrays, never shell strings. The first element must be a tool found in a configured toolchain, such as `opt` or `circt-opt`. Use `{input}`, `{out}` and `{tmp}` as placeholders.
|
|
90
91
|
|
|
92
|
+
## When clang crashes
|
|
93
|
+
|
|
94
|
+
When clang crashes, it prints the paths of a preprocessed source and a run script, such as `/tmp/foo-abc123.c` and `/tmp/foo-abc123.sh`. Pass the script, or the whole crash output, to `from_clang_crash`. It reruns the script's `clang -cc1` command, returns the crash signature and says where the crash is:
|
|
95
|
+
|
|
96
|
+
- `backend`: in the LLVM optimizer or code generator. irsmith emits IR with the same flags plus `-emit-llvm -disable-llvm-passes`, and checks that compiling that IR with the same flags and `-x ir` crashes the same way. llvm-reduce then reduces the IR.
|
|
97
|
+
- `frontend`: in parsing, Sema or IR generation. cvise reduces the preprocessed source, if it is installed.
|
|
98
|
+
|
|
99
|
+
irsmith reads the stage from the stack trace when clang prints one. Unless that shows a frontend crash, it also emits the IR: if emitting it already crashes the same way, the crash is in the frontend. Apple clang prints no stack trace, so there the IR check alone decides. With `reduce: true`, the call also starts the reduce job. Each candidate must crash with the same signature, and `find_duplicates` takes the signature id as usual.
|
|
100
|
+
|
|
101
|
+
On llvm/llvm-project#151623, a "Cannot select" error in the x86 backend, Apple clang 21's crash script was enough: irsmith placed the crash in the backend and reduced the 63-line IR to 12 lines around one SSE4.1 intrinsic call in 12 s.
|
|
102
|
+
|
|
103
|
+
irsmith runs the clang that the script names, which must be an absolute path to a file named `clang`, `clang++` or `clang-<version>`. With `toolchain` set, it runs that toolchain's clang instead.
|
|
104
|
+
|
|
91
105
|
## Configuration
|
|
92
106
|
|
|
93
107
|
Environment variables: `IRSMITH_LLVM_BUILD`, `IRSMITH_CIRCT_BUILD`, `IRSMITH_STATE_DIR` (default `~/.cache/irsmith`), `IRSMITH_ALIVE_TV` and `IRSMITH_CONFIG`. Without them, irsmith looks for Homebrew LLVM, `/usr/lib/llvm-*` and tools on `PATH`. When `gh` is not logged in, `GITHUB_TOKEN` raises the GitHub search rate limit.
|
|
@@ -126,7 +140,7 @@ build_dir = "/path/to/circt/build"
|
|
|
126
140
|
Not done yet:
|
|
127
141
|
|
|
128
142
|
- `prove`: check a transformation with Alive2. The `reduce` oracle for miscompiles also needs it.
|
|
129
|
-
- cvise for C and C++
|
|
143
|
+
- cvise in `reduce` for C and C++ files that do not come from a clang crash report, and `.fir` input for circt-reduce.
|
|
130
144
|
- Testing on Linux.
|
|
131
145
|
|
|
132
146
|
## Development
|
|
@@ -135,7 +149,7 @@ Not done yet:
|
|
|
135
149
|
uv run pytest
|
|
136
150
|
```
|
|
137
151
|
|
|
138
|
-
The integration tests use the builds in `IRSMITH_LLVM_BUILD` and `IRSMITH_CIRCT_BUILD` and are skipped when those are missing.
|
|
152
|
+
The integration tests use the builds in `IRSMITH_LLVM_BUILD` and `IRSMITH_CIRCT_BUILD` and are skipped when those are missing. The clang tests use the clang in `IRSMITH_LLVM_BUILD`, else the one on `PATH`.
|
|
139
153
|
|
|
140
154
|
## License
|
|
141
155
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# irsmith
|
|
2
2
|
|
|
3
|
-
irsmith is an MCP server that lets coding agents debug LLVM, MLIR and CIRCT tools using your own local builds. It runs a compiler command and reads the crash signature, shrinks a crashing input to a small reproducer, and shows which pass changed the IR and how.
|
|
3
|
+
irsmith is an MCP server that lets coding agents debug LLVM, MLIR and CIRCT tools using your own local builds. It runs a compiler command and reads the crash signature, shrinks a crashing input to a small reproducer, and shows which pass changed the IR and how. It can also start from the report that clang prints when it crashes.
|
|
4
4
|
|
|
5
5
|
<!-- mcp-name: io.github.ambujone/irsmith -->
|
|
6
6
|
|
|
@@ -52,12 +52,26 @@ Any MCP client that can launch a stdio server works the same way: the command is
|
|
|
52
52
|
| `diff_passes` | Runs a pipeline with `opt -print-changed`, or with `--mlir-print-ir-after-all --mlir-print-ir-after-change` for `mlir-opt` and `circt-opt`, and returns one diff hunk per pass that changed the IR, within a token budget. If the tool crashes partway, it returns the passes that finished and the crash signature. |
|
|
53
53
|
| `reduce` | Shrinks a crashing `.ll`, `.bc` or `.mir` file with llvm-reduce, or a `.mlir` file with circt-reduce. Each candidate must crash with the same signature as the original, so the reducer cannot drift to a different bug. Runs as a job. |
|
|
54
54
|
| `bisect` | Finds the commit that introduced a crash, or with `find: "fix"` the commit that fixed it. At each step it checks out the commit, runs `ninja -C <build> <targets>` in your build dir and runs the command. A failed build or an unclear result skips the commit. Runs as a job. |
|
|
55
|
+
| `from_clang_crash` | Starts from the run script that clang prints when it crashes. Reruns its `clang -cc1` command, returns the crash signature and whether the crash is in the frontend or in LLVM, and can reduce it. See [When clang crashes](https://github.com/ambujone/irsmith#when-clang-crashes). |
|
|
55
56
|
| `find_duplicates` | Searches GitHub issues for the same crash, given a signature id, a stderr handle or pasted text. Runs up to 3 searches (the assertion text, the top frame, the pass) and ranks the issues by how well they match. Uses `gh` when it is logged in, else the public API. Results are cached for 24 hours. |
|
|
56
57
|
| `job_status`, `job_cancel` | Follow or stop a `reduce` or `bisect` job. Calls wait at most 55 seconds, because many clients drop longer calls. |
|
|
57
58
|
| `read_artifact` | Reads part of a stored output (stderr, IR dumps, the reduced file) by handle, with offset, limit and grep. |
|
|
58
59
|
|
|
59
60
|
Commands are argv arrays, never shell strings. The first element must be a tool found in a configured toolchain, such as `opt` or `circt-opt`. Use `{input}`, `{out}` and `{tmp}` as placeholders.
|
|
60
61
|
|
|
62
|
+
## When clang crashes
|
|
63
|
+
|
|
64
|
+
When clang crashes, it prints the paths of a preprocessed source and a run script, such as `/tmp/foo-abc123.c` and `/tmp/foo-abc123.sh`. Pass the script, or the whole crash output, to `from_clang_crash`. It reruns the script's `clang -cc1` command, returns the crash signature and says where the crash is:
|
|
65
|
+
|
|
66
|
+
- `backend`: in the LLVM optimizer or code generator. irsmith emits IR with the same flags plus `-emit-llvm -disable-llvm-passes`, and checks that compiling that IR with the same flags and `-x ir` crashes the same way. llvm-reduce then reduces the IR.
|
|
67
|
+
- `frontend`: in parsing, Sema or IR generation. cvise reduces the preprocessed source, if it is installed.
|
|
68
|
+
|
|
69
|
+
irsmith reads the stage from the stack trace when clang prints one. Unless that shows a frontend crash, it also emits the IR: if emitting it already crashes the same way, the crash is in the frontend. Apple clang prints no stack trace, so there the IR check alone decides. With `reduce: true`, the call also starts the reduce job. Each candidate must crash with the same signature, and `find_duplicates` takes the signature id as usual.
|
|
70
|
+
|
|
71
|
+
On llvm/llvm-project#151623, a "Cannot select" error in the x86 backend, Apple clang 21's crash script was enough: irsmith placed the crash in the backend and reduced the 63-line IR to 12 lines around one SSE4.1 intrinsic call in 12 s.
|
|
72
|
+
|
|
73
|
+
irsmith runs the clang that the script names, which must be an absolute path to a file named `clang`, `clang++` or `clang-<version>`. With `toolchain` set, it runs that toolchain's clang instead.
|
|
74
|
+
|
|
61
75
|
## Configuration
|
|
62
76
|
|
|
63
77
|
Environment variables: `IRSMITH_LLVM_BUILD`, `IRSMITH_CIRCT_BUILD`, `IRSMITH_STATE_DIR` (default `~/.cache/irsmith`), `IRSMITH_ALIVE_TV` and `IRSMITH_CONFIG`. Without them, irsmith looks for Homebrew LLVM, `/usr/lib/llvm-*` and tools on `PATH`. When `gh` is not logged in, `GITHUB_TOKEN` raises the GitHub search rate limit.
|
|
@@ -96,7 +110,7 @@ build_dir = "/path/to/circt/build"
|
|
|
96
110
|
Not done yet:
|
|
97
111
|
|
|
98
112
|
- `prove`: check a transformation with Alive2. The `reduce` oracle for miscompiles also needs it.
|
|
99
|
-
- cvise for C and C++
|
|
113
|
+
- cvise in `reduce` for C and C++ files that do not come from a clang crash report, and `.fir` input for circt-reduce.
|
|
100
114
|
- Testing on Linux.
|
|
101
115
|
|
|
102
116
|
## Development
|
|
@@ -105,7 +119,7 @@ Not done yet:
|
|
|
105
119
|
uv run pytest
|
|
106
120
|
```
|
|
107
121
|
|
|
108
|
-
The integration tests use the builds in `IRSMITH_LLVM_BUILD` and `IRSMITH_CIRCT_BUILD` and are skipped when those are missing.
|
|
122
|
+
The integration tests use the builds in `IRSMITH_LLVM_BUILD` and `IRSMITH_CIRCT_BUILD` and are skipped when those are missing. The clang tests use the clang in `IRSMITH_LLVM_BUILD`, else the one on `PATH`.
|
|
109
123
|
|
|
110
124
|
## License
|
|
111
125
|
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "irsmith"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.3.0"
|
|
4
4
|
description = "MCP server that helps coding agents debug LLVM, MLIR and CIRCT crashes and pass pipelines"
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
license = "MIT OR Apache-2.0"
|
|
7
7
|
license-files = ["LICENSE-MIT", "LICENSE-APACHE"]
|
|
8
8
|
authors = [
|
|
9
|
-
{ name = "Ambuj
|
|
9
|
+
{ name = "Ambuj A.", email = "ambujone@gmail.com" }
|
|
10
10
|
]
|
|
11
11
|
requires-python = ">=3.11"
|
|
12
12
|
keywords = ["mcp", "mcp-server", "llvm", "mlir", "circt", "compiler", "crash", "debugging", "reduce", "bisect"]
|
|
@@ -47,7 +47,8 @@ packages = ["src/irsmith"]
|
|
|
47
47
|
|
|
48
48
|
[tool.pytest.ini_options]
|
|
49
49
|
testpaths = ["tests"]
|
|
50
|
-
markers = ["llvm: needs the LLVM build in IRSMITH_LLVM_BUILD", "circt: needs the CIRCT build in IRSMITH_CIRCT_BUILD"
|
|
50
|
+
markers = ["llvm: needs the LLVM build in IRSMITH_LLVM_BUILD", "circt: needs the CIRCT build in IRSMITH_CIRCT_BUILD",
|
|
51
|
+
"clang: needs a clang, from IRSMITH_LLVM_BUILD or on PATH"]
|
|
51
52
|
|
|
52
53
|
[dependency-groups]
|
|
53
54
|
dev = [
|
|
@@ -7,12 +7,12 @@
|
|
|
7
7
|
"url": "https://github.com/ambujone/irsmith",
|
|
8
8
|
"source": "github"
|
|
9
9
|
},
|
|
10
|
-
"version": "0.
|
|
10
|
+
"version": "0.3.0",
|
|
11
11
|
"packages": [
|
|
12
12
|
{
|
|
13
13
|
"registryType": "pypi",
|
|
14
14
|
"identifier": "irsmith",
|
|
15
|
-
"version": "0.
|
|
15
|
+
"version": "0.3.0",
|
|
16
16
|
"runtimeHint": "uvx",
|
|
17
17
|
"transport": {
|
|
18
18
|
"type": "stdio"
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
"""The `from_clang_crash` tool: start from the run script that a crashing clang leaves behind."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import os
|
|
6
|
+
import re
|
|
7
|
+
import shlex
|
|
8
|
+
import shutil
|
|
9
|
+
from dataclasses import dataclass
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
from typing import Literal
|
|
12
|
+
|
|
13
|
+
from ..app import App, existing_file, substitute
|
|
14
|
+
from ..config import INSTALL_HINTS, Toolchain
|
|
15
|
+
from ..errors import IrsmithError
|
|
16
|
+
from ..jobs import Job
|
|
17
|
+
from ..models import ClangCrashOutput, ClangStage, OracleRequest, ReduceResult
|
|
18
|
+
from ..oracle.check import REJECT
|
|
19
|
+
from ..pipeline.run import run_in_job
|
|
20
|
+
from ..reduce.driver import reduce_file
|
|
21
|
+
from ..signature.normalize import signature_key
|
|
22
|
+
from ..signature.report import CrashReport
|
|
23
|
+
from ..store import JobDir
|
|
24
|
+
from .script import CrashScript, compile_args, emit_ir_args, ir_args, read_script, script_from_stderr
|
|
25
|
+
|
|
26
|
+
_CLANG_NAME = re.compile(r"clang(\+\+)?(-\d+(\.\d+)*)?")
|
|
27
|
+
_ENTRY = re.compile(r"^\d+\.\s+(?P<entry>.*?)\s*$", re.M)
|
|
28
|
+
_BACKEND_ENTRIES = ("Optimizer", "Code generation")
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
@dataclass
|
|
32
|
+
class Plan:
|
|
33
|
+
"""What a reduce job needs, worked out by inspect()."""
|
|
34
|
+
|
|
35
|
+
exe: Path
|
|
36
|
+
chain: Toolchain | None
|
|
37
|
+
reducer: Literal["llvm-reduce", "cvise"]
|
|
38
|
+
reducer_exe: Path
|
|
39
|
+
input: Path
|
|
40
|
+
argv: list[str]
|
|
41
|
+
expected: str
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def stack_entries(stderr: str) -> list[str]:
|
|
45
|
+
"""The pretty stack trace entries after "Stack dump:", without the program arguments."""
|
|
46
|
+
_, found, rest = stderr.partition("Stack dump:\n")
|
|
47
|
+
if not found:
|
|
48
|
+
return []
|
|
49
|
+
return [e for e in _ENTRY.findall(rest) if not e.startswith("Program arguments:")]
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def stage_from_stack(stderr: str, report: CrashReport) -> tuple[ClangStage, str | None]:
|
|
53
|
+
"""Where clang crashed, judged by the pass and the pretty stack trace."""
|
|
54
|
+
if report.pass_name:
|
|
55
|
+
return "backend", f"the crash is in pass {report.pass_name}"
|
|
56
|
+
entries = stack_entries(stderr)
|
|
57
|
+
for entry in entries:
|
|
58
|
+
if entry in _BACKEND_ENTRIES or entry.startswith("Running pass"):
|
|
59
|
+
return "backend", f'stack entry "{entry[:120]}"'
|
|
60
|
+
if entries:
|
|
61
|
+
return "frontend", f'stack entry "{entries[-1][:120]}"'
|
|
62
|
+
return "unknown", None
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def resolve_clang(app: App, named: str, toolchain: str | None) -> tuple[Toolchain | None, Path]:
|
|
66
|
+
"""The clang to run: the toolchain's when one is named, else the one the script names."""
|
|
67
|
+
if toolchain:
|
|
68
|
+
return app.config.resolve("clang", toolchain)
|
|
69
|
+
path = Path(named)
|
|
70
|
+
real = path.resolve()
|
|
71
|
+
for chain in app.config.toolchains:
|
|
72
|
+
for tool, exe in chain.tools.items():
|
|
73
|
+
if tool.startswith("clang") and exe.resolve() == real:
|
|
74
|
+
return chain, exe
|
|
75
|
+
if path.is_absolute() and _CLANG_NAME.fullmatch(path.name) and path.is_file() and os.access(path, os.X_OK):
|
|
76
|
+
return None, path
|
|
77
|
+
raise IrsmithError("tool_not_found", f"the run script runs {named!r}, which is not an executable clang",
|
|
78
|
+
hint="pass toolchain to run the command with a clang that doctor lists")
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def _argv(exe: Path, args: list[str], input: Path) -> list[str]:
|
|
82
|
+
return [str(exe), *substitute(args, {"input": str(input)})]
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def _same(a: CrashReport, b: CrashReport) -> bool:
|
|
86
|
+
return a.kind == b.kind and signature_key(a) == signature_key(b)
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
async def inspect(app: App, script: str | None, source: str | None, stderr: str | None, toolchain: str | None,
|
|
90
|
+
reducer: str, timeout_s: float) -> tuple[ClangCrashOutput, Plan | None, IrsmithError | None]:
|
|
91
|
+
"""Run the crash script's -cc1 command, find the stage and pick a reducer.
|
|
92
|
+
|
|
93
|
+
Returns the output, the plan for a reduce job, and why there is no plan when there is none."""
|
|
94
|
+
if (script is None) == (stderr is None):
|
|
95
|
+
raise IrsmithError("invalid_argument", "pass one of script or stderr")
|
|
96
|
+
script_path = existing_file(script) if script else existing_file(str(script_from_stderr(stderr or "")))
|
|
97
|
+
crash = read_script(script_path, existing_file(source) if source else None)
|
|
98
|
+
chain, exe = resolve_clang(app, crash.clang, toolchain)
|
|
99
|
+
job = app.store.new_job("run")
|
|
100
|
+
try:
|
|
101
|
+
return await _inspect(app, job, crash, chain, exe, reducer, timeout_s)
|
|
102
|
+
finally:
|
|
103
|
+
job.finish()
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
async def _inspect(app: App, job: JobDir, crash: CrashScript, chain: Toolchain | None, exe: Path, reducer: str,
|
|
107
|
+
timeout_s: float) -> tuple[ClangCrashOutput, Plan | None, IrsmithError | None]:
|
|
108
|
+
argv = _argv(exe, compile_args(crash.args), crash.source)
|
|
109
|
+
job.file("command.sh").write_text(shlex.join(argv) + "\n")
|
|
110
|
+
run, report = await run_in_job(app, job, argv, chain, "clang", timeout_s)
|
|
111
|
+
out = ClangCrashOutput(clang=str(exe), toolchain=chain.name if chain else None, clang_version=crash.version,
|
|
112
|
+
source=str(crash.source), crashed=report.kind not in REJECT, run=run,
|
|
113
|
+
artifacts={"command": job.handle("command.sh")})
|
|
114
|
+
if not out.crashed:
|
|
115
|
+
out.notes.append(f"the -cc1 command ended as {report.kind}, not a crash")
|
|
116
|
+
return out, None, IrsmithError("not_reproducible", "the -cc1 command does not crash with this clang")
|
|
117
|
+
|
|
118
|
+
stderr = app.store.resolve(run.artifacts["stderr"]).read_text(errors="replace")
|
|
119
|
+
out.stage, out.stage_evidence = stage_from_stack(stderr, report)
|
|
120
|
+
ir = job.file("crash.ll")
|
|
121
|
+
if out.stage != "frontend":
|
|
122
|
+
emit_args = emit_ir_args(crash.args, str(ir))
|
|
123
|
+
_, emitted = await run_in_job(app, job, _argv(exe, emit_args, crash.source), chain, "clang", timeout_s,
|
|
124
|
+
name="emit_ir", remember=False)
|
|
125
|
+
if emitted.kind == "clean" and ir.is_file():
|
|
126
|
+
_, compiled = await run_in_job(app, job, _argv(exe, ir_args(crash.args), ir), chain, "clang", timeout_s,
|
|
127
|
+
name="ir_run", remember=False)
|
|
128
|
+
out.ir_reproduces = _same(compiled, report)
|
|
129
|
+
if out.ir_reproduces and out.stage == "unknown":
|
|
130
|
+
out.stage, out.stage_evidence = "backend", "IR from -emit-llvm -disable-llvm-passes crashes the same way"
|
|
131
|
+
elif not out.ir_reproduces:
|
|
132
|
+
out.notes.append(f"the IR from -emit-llvm -disable-llvm-passes ended as {compiled.kind}, "
|
|
133
|
+
"not the same crash, when compiled with -x ir")
|
|
134
|
+
job.pin(ir.name)
|
|
135
|
+
out.artifacts["ir"] = job.handle(ir.name)
|
|
136
|
+
out.paths["ir"] = str(ir)
|
|
137
|
+
elif _same(emitted, report):
|
|
138
|
+
out.ir_reproduces = False
|
|
139
|
+
out.stage, out.stage_evidence = "frontend", "emitting IR with -disable-llvm-passes crashes the same way"
|
|
140
|
+
else:
|
|
141
|
+
out.notes.append(f"emitting IR with -disable-llvm-passes ended as {emitted.kind}")
|
|
142
|
+
|
|
143
|
+
plan, problem = _plan(app, crash, chain, exe, reducer, out, ir, signature_key(report))
|
|
144
|
+
if plan:
|
|
145
|
+
out.reducer = plan.reducer
|
|
146
|
+
elif problem:
|
|
147
|
+
out.notes.append(problem.info.message + (f" ({problem.info.hint})" if problem.info.hint else ""))
|
|
148
|
+
return out, plan, problem
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
def _plan(app: App, crash: CrashScript, chain: Toolchain | None, exe: Path, reducer: str, out: ClangCrashOutput,
|
|
152
|
+
ir: Path, expected: str) -> tuple[Plan | None, IrsmithError | None]:
|
|
153
|
+
if reducer == "llvm-reduce" or reducer == "auto" and out.ir_reproduces:
|
|
154
|
+
if not out.ir_reproduces:
|
|
155
|
+
return None, IrsmithError("not_reproducible", "llvm-reduce needs IR that crashes the same way, "
|
|
156
|
+
"and this crash has none", hint="use reducer = cvise")
|
|
157
|
+
own = chain is not None and "llvm-reduce" in chain.tools
|
|
158
|
+
try:
|
|
159
|
+
reducer_chain, reducer_exe = app.config.resolve("llvm-reduce", chain.name if own else None)
|
|
160
|
+
except IrsmithError as e:
|
|
161
|
+
return None, e
|
|
162
|
+
if not own:
|
|
163
|
+
out.notes.append(f"llvm-reduce is from toolchain {reducer_chain.name if reducer_chain else '?'}, not this "
|
|
164
|
+
"clang's own LLVM. If it cannot read the IR, use reducer = cvise")
|
|
165
|
+
return Plan(exe, chain, "llvm-reduce", reducer_exe, ir, [str(exe), *ir_args(crash.args)], expected), None
|
|
166
|
+
found = shutil.which("cvise")
|
|
167
|
+
if not found:
|
|
168
|
+
return None, IrsmithError("optional_tool_missing", "reducing the source needs cvise, which is not installed",
|
|
169
|
+
hint=INSTALL_HINTS["cvise"])
|
|
170
|
+
return Plan(exe, chain, "cvise", Path(found), crash.source, [str(exe), *compile_args(crash.args)], expected), None
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
async def reduce_crash(app: App, job: Job, plan: Plan, jobs: int | None) -> ReduceResult:
|
|
174
|
+
return await reduce_file(app, job, plan.input, plan.argv, plan.chain, OracleRequest(), plan.reducer,
|
|
175
|
+
plan.reducer_exe, jobs, tool="clang", expected=plan.expected)
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
"""Read the reproducer that the clang driver writes when the compiler crashes.
|
|
2
|
+
|
|
3
|
+
The driver writes `<name>.sh` next to the preprocessed source, such as
|
|
4
|
+
`<name>.c` (Driver::generateCompilationDiagnostics and Command::Print in
|
|
5
|
+
clang/lib/Driver). The script has comment lines, then one line with the -cc1
|
|
6
|
+
command, each argument in double quotes with `"`, `\\` and `$` escaped. That
|
|
7
|
+
line names the source by its file name alone and has no -o.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
import re
|
|
13
|
+
from dataclasses import dataclass
|
|
14
|
+
from pathlib import Path
|
|
15
|
+
|
|
16
|
+
from ..errors import IrsmithError
|
|
17
|
+
|
|
18
|
+
_DIAG_PATH = re.compile(r"diagnostic msg: (/.*?)\s*$", re.M)
|
|
19
|
+
_SH_PATH = re.compile(r"(/[^\s'\"]+\.sh)\b")
|
|
20
|
+
_VERSION = re.compile(r"^# Crash reproducer for (.*)$", re.M)
|
|
21
|
+
# Actions that pick the -cc1 output. The IR route replaces them.
|
|
22
|
+
_ACTIONS = {"-emit-obj", "-S", "-emit-llvm", "-emit-llvm-bc", "-emit-llvm-only", "-emit-codegen-only",
|
|
23
|
+
"-emit-assembly", "-fsyntax-only"}
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
@dataclass
|
|
27
|
+
class CrashScript:
|
|
28
|
+
script: Path
|
|
29
|
+
source: Path
|
|
30
|
+
clang: str # the executable as the script names it
|
|
31
|
+
args: list[str] # the arguments after it, with {input} where the source goes
|
|
32
|
+
version: str | None
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def split_command(line: str) -> list[str]:
|
|
36
|
+
"""Split a command line printed by llvm::sys::printArg."""
|
|
37
|
+
words, i = [], 0
|
|
38
|
+
while i < len(line):
|
|
39
|
+
if line[i].isspace():
|
|
40
|
+
i += 1
|
|
41
|
+
continue
|
|
42
|
+
word = []
|
|
43
|
+
while i < len(line) and not line[i].isspace():
|
|
44
|
+
if line[i] != '"':
|
|
45
|
+
word.append(line[i])
|
|
46
|
+
i += 1
|
|
47
|
+
continue
|
|
48
|
+
i += 1
|
|
49
|
+
while i < len(line) and line[i] != '"':
|
|
50
|
+
if line[i] == "\\" and i + 1 < len(line):
|
|
51
|
+
i += 1
|
|
52
|
+
word.append(line[i])
|
|
53
|
+
i += 1
|
|
54
|
+
if i == len(line):
|
|
55
|
+
raise IrsmithError("invalid_argument", "the run script has an unterminated quote")
|
|
56
|
+
i += 1
|
|
57
|
+
words.append("".join(word))
|
|
58
|
+
return words
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def script_from_stderr(text: str) -> Path:
|
|
62
|
+
"""The run script path in clang's crash output."""
|
|
63
|
+
paths = [p for p in _DIAG_PATH.findall(text) if p.endswith(".sh")] or _SH_PATH.findall(text)
|
|
64
|
+
if not paths:
|
|
65
|
+
raise IrsmithError("invalid_argument", "found no run script (.sh) path in the text",
|
|
66
|
+
hint="pass the clang output that lists the preprocessed source and run script")
|
|
67
|
+
return Path(paths[-1])
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def read_script(script: Path, source: Path | None = None) -> CrashScript:
|
|
71
|
+
text = script.read_text(errors="replace")
|
|
72
|
+
if "Arguments passed via response file" in text:
|
|
73
|
+
raise IrsmithError("unsupported_input", "the run script passes its arguments in a response file")
|
|
74
|
+
lines = [line for line in text.splitlines() if line.strip() and not line.lstrip().startswith("#")]
|
|
75
|
+
if not lines:
|
|
76
|
+
raise IrsmithError("invalid_argument", f"{script} has no command")
|
|
77
|
+
argv = split_command(lines[-1])
|
|
78
|
+
if len(argv) < 2 or argv[1] != "-cc1":
|
|
79
|
+
raise IrsmithError("unsupported_input", "the run script does not run clang -cc1",
|
|
80
|
+
hint="only crashes of the compiler itself have a -cc1 reproducer")
|
|
81
|
+
args = argv[1:]
|
|
82
|
+
|
|
83
|
+
# The source is named like the script, as <stem>.<ext>, or by the name of the file passed in.
|
|
84
|
+
names = {source.name} if source else set()
|
|
85
|
+
found = [i for i, arg in enumerate(args)
|
|
86
|
+
if args[i - 1] != "-main-file-name" and not arg.startswith("-")
|
|
87
|
+
and (Path(arg).stem == script.stem or arg in names)]
|
|
88
|
+
if not found:
|
|
89
|
+
raise IrsmithError("invalid_argument", f"the -cc1 command in {script.name} does not name a file like {script.stem}.c",
|
|
90
|
+
hint="pass source, the preprocessed file that clang printed next to the script")
|
|
91
|
+
index = found[-1]
|
|
92
|
+
if source is None:
|
|
93
|
+
source = script.parent / args[index]
|
|
94
|
+
if not source.is_file():
|
|
95
|
+
raise IrsmithError("invalid_argument", f"{source} does not exist",
|
|
96
|
+
hint="pass source, the preprocessed file that clang printed next to the script")
|
|
97
|
+
args[index] = "{input}"
|
|
98
|
+
_absolute_crash_paths(args, script.parent)
|
|
99
|
+
m = _VERSION.search(text)
|
|
100
|
+
return CrashScript(script=script, source=source, clang=argv[0], args=args, version=m.group(1).strip() if m else None)
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def _absolute_crash_paths(args: list[str], directory: Path) -> None:
|
|
104
|
+
"""Make the module crash paths absolute. The script names them relative to its own directory."""
|
|
105
|
+
for i, arg in enumerate(args):
|
|
106
|
+
if i and args[i - 1] == "-ivfsoverlay" and not arg.startswith("/"):
|
|
107
|
+
args[i] = str(directory / arg)
|
|
108
|
+
elif arg.startswith("-fmodules-cache-path=") and not arg.split("=", 1)[1].startswith("/"):
|
|
109
|
+
args[i] = "-fmodules-cache-path=" + str(directory / arg.split("=", 1)[1])
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def _without_language(args: list[str]) -> list[str]:
|
|
113
|
+
out, skip = [], False
|
|
114
|
+
for arg in args:
|
|
115
|
+
if skip:
|
|
116
|
+
skip = False
|
|
117
|
+
elif arg == "-x":
|
|
118
|
+
skip = True
|
|
119
|
+
elif arg not in _ACTIONS:
|
|
120
|
+
out.append(arg)
|
|
121
|
+
return out
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
def compile_args(args: list[str]) -> list[str]:
|
|
125
|
+
"""The script's command, writing its output nowhere."""
|
|
126
|
+
return [*args, "-o", "/dev/null"]
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
def emit_ir_args(args: list[str], out: str) -> list[str]:
|
|
130
|
+
"""The same flags, stopping after IR generation with no LLVM passes run."""
|
|
131
|
+
return [*(arg for arg in args if arg not in _ACTIONS), "-emit-llvm", "-disable-llvm-passes", "-o", out]
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
def ir_args(args: list[str]) -> list[str]:
|
|
135
|
+
"""The same flags and action, compiling an IR file at {input} instead of the source."""
|
|
136
|
+
action = [arg for arg in args if arg in _ACTIONS and arg != "-fsyntax-only"] or ["-emit-obj"]
|
|
137
|
+
rest = [arg for arg in _without_language(args) if arg != "{input}"]
|
|
138
|
+
return [*rest, *action, "-x", "ir", "{input}", "-o", "/dev/null"]
|
|
@@ -23,7 +23,7 @@ LLVM_TOOLS = ["opt", "llc", "clang", "clang++", "llvm-reduce", "llvm-as", "llvm-
|
|
|
23
23
|
CIRCT_TOOLS = ["circt-opt", "firtool", "circt-reduce", "circt-translate", "circt-verilog", "arcilator"]
|
|
24
24
|
_GITHUB_REPOS = {"llvm": "llvm/llvm-project", "circt": "llvm/circt"}
|
|
25
25
|
_PRIMARY = ["opt", "circt-opt", "firtool", "mlir-opt", "clang", "llc"]
|
|
26
|
-
|
|
26
|
+
INSTALL_HINTS = {
|
|
27
27
|
"alive_tv": "build alive2 against the same LLVM as your opt, then set IRSMITH_ALIVE_TV or [tools] alive_tv",
|
|
28
28
|
"alive_plugin": "build alive2 with the tv plugin, then set [tools] alive_plugin",
|
|
29
29
|
"cvise": "brew install cvise, or apt install cvise",
|
|
@@ -232,7 +232,7 @@ async def doctor(config: Config, state_bytes: int, state_jobs: int) -> DoctorOut
|
|
|
232
232
|
toolchains=infos,
|
|
233
233
|
optional={
|
|
234
234
|
name: OptionalTool(found=True, path=str(path)) if path and Path(path).exists()
|
|
235
|
-
else OptionalTool(found=False, install_hint=
|
|
235
|
+
else OptionalTool(found=False, install_hint=INSTALL_HINTS[name])
|
|
236
236
|
for name, path in optional.items()
|
|
237
237
|
},
|
|
238
238
|
state_dir=StateDirInfo(path=str(config.state_dir), bytes=state_bytes, jobs=state_jobs),
|
|
@@ -201,6 +201,7 @@ class DiffPassesOutput(Model):
|
|
|
201
201
|
)
|
|
202
202
|
notes: list[str] = []
|
|
203
203
|
artifacts: dict[str, str]
|
|
204
|
+
paths: dict[str, str] = {}
|
|
204
205
|
|
|
205
206
|
|
|
206
207
|
# find_duplicates
|
|
@@ -266,3 +267,31 @@ class BisectResult(Model):
|
|
|
266
267
|
build_dir_rebuilt: bool
|
|
267
268
|
notes: list[str] = []
|
|
268
269
|
artifacts: dict[str, str]
|
|
270
|
+
paths: dict[str, str] = {}
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
# from_clang_crash
|
|
274
|
+
|
|
275
|
+
ClangStage = Literal["frontend", "backend", "unknown"]
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
class ClangCrashOutput(Model):
|
|
279
|
+
clang: str = Field(description="The clang that ran the -cc1 command.")
|
|
280
|
+
toolchain: str | None
|
|
281
|
+
clang_version: str | None = Field(None, description="From the run script's header.")
|
|
282
|
+
source: str
|
|
283
|
+
crashed: bool = Field(description="False when the -cc1 command did not crash with this clang.")
|
|
284
|
+
run: RunOutput
|
|
285
|
+
stage: ClangStage | None = Field(
|
|
286
|
+
None, description="frontend: before LLVM passes run (parsing, Sema, IR generation). backend: in the "
|
|
287
|
+
"optimizer or code generator.")
|
|
288
|
+
stage_evidence: str | None = None
|
|
289
|
+
ir_reproduces: bool | None = Field(
|
|
290
|
+
None, description="Whether IR emitted with -emit-llvm -disable-llvm-passes crashes the same way when compiled "
|
|
291
|
+
"with the same flags and -x ir. Null when not tried.")
|
|
292
|
+
reducer: Literal["llvm-reduce", "cvise"] | None = Field(
|
|
293
|
+
None, description="The reducer that fits: llvm-reduce on the IR, or cvise on the source.")
|
|
294
|
+
job: JobStatus | None = Field(None, description="The reduce job, when reduce = true.")
|
|
295
|
+
notes: list[str] = []
|
|
296
|
+
artifacts: dict[str, str]
|
|
297
|
+
paths: dict[str, str] = {}
|
|
@@ -5,9 +5,11 @@ from __future__ import annotations
|
|
|
5
5
|
import signal as signals
|
|
6
6
|
|
|
7
7
|
from ..app import App, existing_file, substitute
|
|
8
|
+
from ..config import Toolchain
|
|
8
9
|
from ..models import RunOutput, Signature
|
|
9
10
|
from ..signature.parse import parse_crash
|
|
10
|
-
from ..
|
|
11
|
+
from ..signature.report import CrashReport
|
|
12
|
+
from ..store import JobDir, strip_ansi
|
|
11
13
|
|
|
12
14
|
MAX_EXCERPT = 8
|
|
13
15
|
_NOISE = ("PLEASE submit a bug report", "Stack dump without symbol names")
|
|
@@ -30,21 +32,28 @@ async def run_command(app: App, command: list[str], input: str | None, toolchain
|
|
|
30
32
|
if input_path:
|
|
31
33
|
values["input"] = str(input_path)
|
|
32
34
|
argv = [str(exe), *substitute(command[1:], values)]
|
|
35
|
+
out, _ = await run_in_job(app, job, argv, chain, command[0], timeout_s)
|
|
36
|
+
job.finish()
|
|
37
|
+
return out
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
async def run_in_job(app: App, job: JobDir, argv: list[str], chain: Toolchain | None, tool: str, timeout_s: float,
|
|
41
|
+
name: str = "run", remember: bool = True) -> tuple[RunOutput, CrashReport]:
|
|
42
|
+
"""Run argv in `job` and classify how it ended. With `remember`, find_duplicates can look the signature up."""
|
|
33
43
|
async with app.light:
|
|
34
|
-
result = await app.run_tool(job, argv, toolchain=chain, name=
|
|
44
|
+
result = await app.run_tool(job, argv, toolchain=chain, name=name, timeout_s=timeout_s)
|
|
35
45
|
stderr = result.stderr.read_text(errors="replace")
|
|
36
46
|
report = parse_crash(stderr, result.exit_code, result.signal)
|
|
37
47
|
if result.timed_out or result.oom_killed:
|
|
38
48
|
report = report._replace(kind="timeout" if result.timed_out else "oom")
|
|
39
|
-
artifacts = {"stdout": job.handle("
|
|
49
|
+
artifacts = {"stdout": job.handle(f"{name}.stdout"), "stderr": job.handle(f"{name}.stderr")}
|
|
40
50
|
if job.file("out").exists():
|
|
41
51
|
artifacts["out"] = job.handle("out")
|
|
42
52
|
signature = None if report.kind == "clean" else Signature.from_report(report)
|
|
43
|
-
if signature:
|
|
44
|
-
app.store.remember_signature(signature, tool=
|
|
53
|
+
if signature and remember:
|
|
54
|
+
app.store.remember_signature(signature, tool=tool, github_repo=chain.github_repo if chain else None,
|
|
45
55
|
stderr=artifacts["stderr"])
|
|
46
|
-
|
|
47
|
-
return RunOutput(
|
|
56
|
+
out = RunOutput(
|
|
48
57
|
exit_code=result.exit_code,
|
|
49
58
|
signal=signals.Signals(result.signal).name if result.signal else None,
|
|
50
59
|
timed_out=result.timed_out,
|
|
@@ -56,3 +65,4 @@ async def run_command(app: App, command: list[str], input: str | None, toolchain
|
|
|
56
65
|
output_truncated=result.truncated,
|
|
57
66
|
artifacts=artifacts,
|
|
58
67
|
)
|
|
68
|
+
return out, report
|