Skip to content
This repository has been archived by the owner on Sep 2, 2018. It is now read-only.

Reducing a test case

Jake Goulding edited this page Oct 9, 2016 · 2 revisions

Starting from LLVM IR

Warning Make sure that you are using your custom-compiled LLVM binaries, and not those provided by the system. You may with to add your LLVM build directory to your PATH or always specify complete paths to each tool.

Ensure that you can reproduce the error:

./bin/llc -march=avr -mcpu=atmega328p -filetype=obj ./reproduction.ll
Assertion failed: (DstReg != SrcReg && "SrcReg and DstReg cannot be the same"), function expand, file /Projects/avr-llvm/lib/Target/AVR/AVRExpandPseudoInsts.cpp, line 817.
Stack dump:
0.	Program arguments: ./bin/llc -march=avr -mcpu=atmega328p -filetype=obj ./reproduction.ll
1.	Running pass 'Function Pass Manager' on module './reproduction.ll'.
2.	Running pass 'AVR pseudo instruction expansion pass' on function '@__udivmodsi4'

Now we will use bugpoint to reduce the LLVM IR to something manageable. I prefer to use the "dumb" mode of bugpoint. I create two scripts to do the test run for me:

bugpoint.sh

#!/bin/bash

export PATH=/path/to/llvm/build/bin/:$PATH

bugpoint $1 -compile-custom -compile-command ./repro.sh

repro.sh

#!/bin/bash

set -eux

! llc -march=avr -mcpu=atmega328p -filetype=obj 2>&1 | grep 'SrcReg and DstReg cannot be the same'

Validate your reproduction script; making sure it says INTERESTING:

./repro.sh < reproduction.ll && echo "NON-INTERESTING" || echo "INTERESTING"

Next, run bugpoint. This can take a while. When it is done, it will tell you where it wrote the output:

Emitted bitcode to 'bugpoint-reduced-simplified.bc'

Convert the bitcode back to LLVM-IR:

./bin/llvm-dis bugpoint-reduced-simplified.bc

Now there should be a file called bugpoint-reduced-simplified.ll. Test that one more time and ensure you get the same error:

./bin/llc -march=avr -mcpu=atmega328p -filetype=obj ./bugpoint-reduced-simplified.ll

Starting from Rust

Perhaps you have some error like this:

cargo build --release --target=./arduino.json
   Compiling core v0.1.0 (file:///Projects/arduino/libcore)
Assertion failed: (DstReg != SrcReg && "SrcReg and DstReg cannot be the same"), function expand, file /Projects/avr-llvm/lib/Target/AVR/AVRExpandPseudoInsts.cpp, line 817.

Find out the rustc invocation that was used:

cargo build --release --target=./arduino.json --verbose
# ...
     Running `rustc /Projects/avr-rust/src/libcore/lib.rs --crate-name core --crate-type lib -C opt-level=3 -C metadata=4061c42bc10dce43 --out-dir /Projects/arduino/blink/target/arduino/release/deps --emit=dep-info,link --target ./arduino.json -L dependency=/Projects/arduino/blink/target/arduino/release/deps`

Grab that invocation and change --emit=dep-info,link to --emit=llvm-ir. Running that will produce a .ll file to continue with the above process.

Clone this wiki locally