Csmith is a tool that can generate random C programs that statically and dynamically conform to the C99 standard. It is useful for stress-testing compilers, static analyzers, and other tools that process C code. Csmith has found bugs in every tool that it has tested, and we have used it to find and report more than 400 previously-unknown compiler bugs.

Publications and Presentations

Finding and Understanding Bugs in C Compilers. In Proc. PLDI 2011. Also see the lists of:

Exposing Difficult Compilers Bugs With Random Testing. In 2010 GCC Developers' Summit.

Hardening LLVM With Random Testing. In 2010 LLVM Developers' Meeting.

Volatiles are Miscompiled, and What to Do About It. In Proc. EMSOFT 2008.

Source Code

Csmith is open source, under a BSD-style license.

Also, the latest development version of Csmith can be found on github.

Csmith used to be called Randprog, and an old page about that tool can be found here.

Building Csmith

To build Csmith you need to have a C++ compiler installed. It should compile without trouble on most any recent Linux, FreeBSD, MacOS, or Windows machine.

On Linux, MacOS, or Windows+Cygwin:

cd [csmith-root]
./configure
make

Standard autoconf options like --prefix should work as expected.

On Windows+VS:

Use the project file at [csmith-root]/src/csmith.vcproj for VC9 or [csmith-root]/src/csmith.vcxproj for VC10.

Using Csmith

Please see Testing Compilers using Csmith.

Feedback

If you find Csmith to be useful, please let us know. Specific feedback provides us with a great incentive to keep improving the tool. Also, it helps us keep our funders happy by demonstrating impact. We recognize that if you are part of a product group, it may not be possible to send us a message talking about how many bugs were found. Even so, we'd appreciate even a short, non-specific note.

If Csmith crashes or generates invalid code, please let us know.

There are two mailing lists:

People