Home / Alt manpages / llvm-stress-18(1)

  • llvm-stress-18(1)
  • User command
  • linux

Generate Reproducible LLVM IR Test Files with llvm-stress-18

You will create a deterministic random LLVM IR file, check that it is usable, and keep the generated case separate from an existing test file. The examples use Ubuntu's llvm-stress-18 from package llvm-18, version 18.1.3-1ubuntu1. Allow about ten minutes if LLVM is already installed.

llvm-stress generates random .ll files for testing LLVM components. It is a test-input generator, not a compiler and not a validator of arbitrary source code. The command does not need elevated privileges when you write into a directory you own.

1. Check the installed command

Confirm the executable and the package version before relying on its options:

$ command -v llvm-stress-18
/usr/bin/llvm-stress-18
$ llvm-stress-18 --version
Ubuntu LLVM version 18.1.3
  Optimized build.
$ dpkg-query -W -f='${Package} ${Version}\n' llvm-18
llvm-18 1:18.1.3-1ubuntu1

The installed manual page documents -o, -size and -seed. The command's own help is the final check for the installed build and also lists --enable-scalable-vectors:

$ llvm-stress-18 --help | grep -E 'enable-scalable-vectors|-o <filename>|--seed|--size'
  --enable-scalable-vectors - Generate IR involving scalable vector types
  -o <filename>             - Override output filename
  --seed=<uint>             - Seed used for randomness
  --size=<uint>             - The estimated size of the generated function (# of instrs)

Checkpoint: if the command is missing, stop here and install the LLVM package through your normal system-management process. Do not substitute a different major version in an automated test without recording that change.

2. Generate a small named test case

Choose a new destination, then provide both a seed and an estimated instruction count:

$ llvm-stress-18 -size=5 -seed=7 -o /tmp/llvm-case-7.ll
$ test -s /tmp/llvm-case-7.ll && echo 'generated: /tmp/llvm-case-7.ll'
generated: /tmp/llvm-case-7.ll

-size controls the estimated size of the generated function, measured in instructions. It is not an exact byte-size limit. -seed selects the random sequence, and -o chooses the output file. The program returns status 0 on success and writes LLVM assembly text to the named file.

Expected output begins with a module header and a generated function. Names, constants and the exact number of lines are data from the chosen seed, so do not compare them to a fixed sample by eye:

$ sed -n '1,12p' /tmp/llvm-case-7.ll
; ModuleID = '/tmp/autogen.bc'
source_filename = "/tmp/autogen.bc"

define void @autogen_SD7(ptr %0, ptr %1, ptr %2, i32 %3, i64 %4, i8 %5) {
BB:
  %A4 = alloca i32, align 4
  %A3 = alloca double, align 8
  %A2 = alloca double, align 8
  %A1 = alloca i64, align 8

The temporary path in the module identifier is normal for this build. It does not mean that the command read an input file.

3. Reproduce the same case with the seed

Run the same command into a second file and compare the hashes:

$ llvm-stress-18 -size=5 -seed=7 -o /tmp/llvm-case-7-again.ll
$ sha256sum /tmp/llvm-case-7.ll /tmp/llvm-case-7-again.ll
8d62fcd391b69223e5a0de44140c458a65161835ddc6a9cd7b4ccbf8d30fb445  /tmp/llvm-case-7.ll
8d62fcd391b69223e5a0de44140c458a65161835ddc6a9cd7b4ccbf8d30fb445  /tmp/llvm-case-7-again.ll

Matching hashes show that this installed version produced identical files for the same options. Record the LLVM version, seed and size alongside a bug report. A different LLVM build or a changed option can produce different IR even when the seed is unchanged.

4. Let the command choose the output stream

If you omit -o, the generated IR is written to standard output. Redirect it only to a new pathname or a deliberately temporary file:

$ llvm-stress-18 -size=5 -seed=7 > /tmp/llvm-case-7-stdout.ll
$ test -s /tmp/llvm-case-7-stdout.ll && head -n 3 /tmp/llvm-case-7-stdout.ll
; ModuleID = '/tmp/autogen.bc'
source_filename = "/tmp/autogen.bc"

This is useful in pipelines, but shell redirection happens before the program starts. The > operator truncates an existing destination immediately. Use a fresh filename when the old file matters. If a command fails after redirection, inspect the result before replacing anything.

5. Validate or feed the test case to another LLVM tool

Generation succeeding does not prove that a later LLVM component accepts the file. If llvm-as-18 is installed, assemble the text into bitcode as a separate check:

$ llvm-as-18 /tmp/llvm-case-7.ll -o /tmp/llvm-case-7.bc
$ test -s /tmp/llvm-case-7.bc && echo 'assembled successfully'
assembled successfully

For a component under test, replace the assembler with that component and preserve the generated .ll file as the reproducible input. Do not assume that random IR is safe to execute: it is test data, and a downstream tool may expose bugs or consume substantial CPU and memory.

6. Avoid accidental replacement and clean up carefully

Never point -o at the only copy of a useful testcase until you have saved its seed and metadata. A safe replacement uses a new file first:

$ llvm-stress-18 -size=100 -seed=42 -o /tmp/new-case.ll
$ test -s /tmp/new-case.ll
$ mv /tmp/new-case.ll ./case.ll

The final mv replaces ./case.ll if it already exists, so use it only after checking the new file. Keep the old file under a different name if you may need it. Removing generated cases is irreversible unless another copy exists; clean up only after the test run and any bug report are complete.

There is no persistent configuration to undo. Each invocation generates a new file or stream. If output is unexpectedly empty, check the exit status and destination permissions, then rerun with a new path. If an option is rejected, use llvm-stress-18 --help rather than copying syntax from another LLVM release.

Done means

  • llvm-stress-18 and its package version are recorded.
  • A non-empty .ll file was generated with an explicit seed, size and safe destination.
  • Repeating the command with the same seed produced the expected reproducible result.
  • The file was checked or passed to the intended downstream LLVM tool.
  • No useful testcase was overwritten or deleted without a retained copy.