A fork of Csmith that generates random programs valid under the SysY language — a simplified C subset used in the PKU compiler course.
| Feature | Original Csmith | sysy-smith |
|---|---|---|
| Types | int, char, short, long, unsigned, … |
int only |
| Integer literals | Any suffix (UL, LL, …), any range |
No suffix, clamped to [0, 2147483647] |
| Operators | Bitwise (&, |, ^, ~), shift (<<, >>) |
Removed |
| Compound assignment | +=, -=, *=, /=, %=, <<=, >>=, &=, |=, ^= |
Removed |
| Increment/decrement | ++, -- (pre and post) |
Removed |
| Type casts | Present | Removed |
for loops |
Present | Removed (SysY only has while) |
struct / union |
Present | Removed |
| Pointers | Present | Removed |
| Arrays | Present | Removed |
static / volatile / const |
Present | Removed |
| Comma operator | Present | Removed |
| Assignment as expression | Present | Removed |
#include / #define / macros |
Present in output | Removed from output |
| Checksum / hash infrastructure | Present | Removed |
- No
#includeor#definedirectives in generated files. main()takes no arguments and returns0unconditionally.- Empty parameter lists use
()instead of(void).
By default (--no-forward-decls), sysy-smith topologically sorts functions so every callee is defined before its callers — no forward declarations are needed. This is required because SysY does not support function declarations.
Pass --forward-decls to restore the original Csmith behaviour (forward declarations emitted, functions in creation order).
Csmith is a random generator of C programs. It's primary purpose is to find compiler bugs with random programs, using differential testing as the test oracle.
Csmith can be used outside of the field of compiler testing. If your application needs a test suite of C programs and you don't bother to write them, feel free to give Csmith a try.
Csmith outputs C programs free of undefined behaviors (believe us, that's not trivial), and the statistics of each generated program.
Pre-built binaries for x86_64 and aarch64 Linux are available on the Releases page.
To build from source (Ubuntu):
git clone https://github.com/hsqStephenZhang/sysy-smith.git
cd sysy-smith
sudo apt install g++ cmake m4
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build --target sysy-smith -j$(nproc)
# binary at build/src/sysy-smithGenerate a random SysY-compatible program and compile it with a SysY compiler:
./sysy-smith --no-argc --seed 42 > test.c
kira -koopa test.c -o test.koopaKey options:
--no-argc— omitargc/argvfrommain(required for SysY)--seed <N>— set the random seed for reproducible output--no-forward-decls— (default) emit functions in dependency order, no forward declarations--forward-decls— emit forward declarations and functions in creation order
Use ./sysy-smith -h or ./sysy-smith -hh to see all available options.
Here is a slightly outdated but still relevant document about using Csmith for compiler testing.
Csmith was originally developed at the University of Utah by:
as part of a research project on compiler testing. The research is best summarized by our paper Finding and Understanding Bugs in C Compilers. More research info can be found here.
Csmith was open sourced in 2009. We try to keep maintaining it as an open source project using our discretionary time. As much, the response to bug reports or feature requests might be delayed.
Please use github issues to report bugs or suggestions.
We have a mailing list for discussing Csmith. Please visit here to subscribe.