2024-11-27 12:56:00
bernsteinbear.com
November 15, 2024
C-Reduce is a tool by Regehr and
friends for minimizing C compiler bug reproducers. Imagine if you had a 10,000
line long C file that triggered a Clang bug. You don’t want to send a massive
blob to the compiler developers because that’s unhelpful, but you also don’t
want to cut it down to size by hand. The good news is that C-Reduce can do that
for you. The bad news is that everyone thinks it only works for C.
It’s pretty widely applicable. You only need:
- A deterministic condition
- A reasonably quick reproducer (it helps with the speed of the reduction)
- One or more mutable source files for C-Reduce to cut down
I ran into a bug with RustPython
running scrapscript and wanted to
report it. So I ran wrote a script interesting.sh
to reproduce the bug:
#!/bin/bash
# No -o pipefail; we don't want rustpython failures to cause the script to fail
set -eu
# Note the absolute path to the binary, which is not in $PATH
/path/to/RustPython/target/release/rustpython scrapscript.py 2>&1 | grep \
"tried to push value onto stack but overflowed max_stackdepth"
And then I ran C-Reduce. This all happened within a couple of seconds:
$ creduce --not-c interesting.sh scrapscript.py
======
running 4 interestingness tests in parallel
======
(0.5 %, 200799 bytes)
(0.6 %, 200607 bytes)
======
(9.2 %, 183225 bytes)
(18.1 %, 165228 bytes)
(26.5 %, 148382 bytes)
(29.3 %, 142674 bytes)
(34.6 %, 131961 bytes)
(38.1 %, 124960 bytes)
(40.6 %, 119872 bytes)
(42.3 %, 116504 bytes)
(44.4 %, 112161 bytes)
(46.4 %, 108180 bytes)
(47.5 %, 105950 bytes)
...
What you see is C-Reduce cutting down the file by 50% nearly instantly… and I
don’t even have a very fast computer.
We use --not-c
because otherwise C-Reduce uses a bunch of C-specific passes.
If we’re working on Python, it will likely just slow things down (but not
materially change the outcome).
There you have it. Fast and easy. As I finish typing these next couple of
sentences, we’re already at 96.9% reduced.
Keep your files stored safely and securely with the SanDisk 2TB Extreme Portable SSD. With over 69,505 ratings and an impressive 4.6 out of 5 stars, this product has been purchased over 8K+ times in the past month. At only $129.99, this Amazon’s Choice product is a must-have for secure file storage.
Help keep private content private with the included password protection featuring 256-bit AES hardware encryption. Order now for just $129.99 on Amazon!
Support Techcratic
If you find value in Techcratic’s insights and articles, consider supporting us with Bitcoin. Your support helps me, as a solo operator, continue delivering high-quality content while managing all the technical aspects, from server maintenance to blog writing, future updates, and improvements. Support Innovation! Thank you.
Bitcoin Address:
bc1qlszw7elx2qahjwvaryh0tkgg8y68enw30gpvge
Please verify this address before sending funds.
Bitcoin QR Code
Simply scan the QR code below to support Techcratic.
Please read the Privacy and Security Disclaimer on how Techcratic handles your support.
Disclaimer: As an Amazon Associate, Techcratic may earn from qualifying purchases.