If you are trying to debug a crash of the compiler you need to reduce your test case to something small.

Compiler writers cannot just take your huge project and find the crash.

For go (golang), at least the gccgo compiler, you pass in a set of files and they are compiled in a package, so the number of files passed to the compiler matters.

I have two simple bash scripts to provoke a compiler crash by first selecting pairs of files to compile and testing them.

After you found the files, you can concatenate them together and select random lines until you can find the exact minimum lines to provoke a crash.

We are using the command shuf from GNU coreutils (https://www.gnu.org/software/coreutils/manual/html_node/shuf-invocation.html) to create random permutations, then use “head -$COUNT” to select COUNT lines from that permutation. This will pick random lines from an input. Then we look for the line “report” in the stderr to look for a sign of the crash, this will end the loop. The program stops when it finds a crash.

Here is the one to select files to compile

rm stop.txt

touch stop.txt

while [ $(wc -l stop.txt | cut -f1 -d ” “) -eq 0 ];

do echo test;

ls *.go | shuf | head -2 | tee test.txt | xargs ~/install/bin/gccgo > out.txt 2>err.txt;

echo $?;

grep report out.txt err.txt > stop.txt;

done

This takes a file with arg 1 and selects n lines with arg 2

rm stop.txt

touch stop.txt

while [ $(wc -l stop.txt | cut -f1 -d ” “) -eq 0 ];

do echo .;

echo “package main” > ~/test.go

cat $1 | shuf | head -$2 >> ~/test.go

~/install/bin/gccgo ~/test.go > out.txt 2>err.txt;

grep report out.txt err.txt > stop.txt;

done cat ~/test.go # show the error

Feedback :