From: Ted Kremenek Date: Mon, 21 May 2012 23:29:01 +0000 (+0000) Subject: Add basic delta-debugging script used for reducing analyzer crasher test cases. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3a4653039524e1518243ae8e77ca10534e50e378;p=clang Add basic delta-debugging script used for reducing analyzer crasher test cases. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@157219 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/utils/analyzer/reducer.pl b/utils/analyzer/reducer.pl new file mode 100755 index 0000000000..f2dac1fc10 --- /dev/null +++ b/utils/analyzer/reducer.pl @@ -0,0 +1,65 @@ +#!/usr/bin/perl -w +use strict; +use File::Temp qw/ tempdir /; +my $prog = "reducer"; + +die "$prog [optional command]\n" if ($#ARGV < 0); +my $file = shift @ARGV; +die "$prog: [error] cannot read file $file\n" if (! -r $file); + +my $magic = shift @ARGV; +die "$prog: [error] no error string specified\n" if (! defined $magic); + +# Create a backup of the fuke. +my $dir = tempdir( CLEANUP => 1 ); +print "$prog: created temporary directory '$dir'\n"; +my $srcFile = "$dir/$file"; +`cp $file $srcFile`; + +# Create the script. +my $scriptFile = "$dir/script"; +open(OUT, ">$scriptFile") or die "$prog: cannot create '$scriptFile'\n"; +my $reduceOut = "$dir/reduceOut"; + +my $command; +if (scalar(@ARGV) > 0) { $command = \@ARGV; } +else { + my $compiler = "/Users/kremenek/llvm-cmake-release/bin/clang"; + $command = [$compiler, "-fsyntax-only", "-Wfatal-errors", "-Wno-deprecated-declarations", "-Wimplicit-function-declaration"]; +} +push @$command, $srcFile; +my $commandStr = "@$command"; + +print OUT <) { + if (/$magic/) { exit \$GOOD; } +} +exit \$BAD; +ENDTEXT +close(OUT); +`chmod +x $scriptFile`; + +print "$prog: starting reduction\n"; +sub multidelta { + my $level = shift @_; + system("multidelta -level=$level $scriptFile $srcFile"); +} + +for (my $i = 1 ; $i <= 5; $i++) { + foreach my $level (0,0,1,1,2,2,10) { + multidelta($level); + } +} + +# Copy the final file. +`cp $srcFile $file.reduced`; +print "$prog: generated '$file.reduced";