[cfe-commits] r157219 - /cfe/trunk/utils/analyzer/reducer.pl

Nick Lewycky nlewycky at google.com
Mon May 21 17:31:20 PDT 2012


On 21 May 2012 16:29, Ted Kremenek <kremenek at apple.com> wrote:

> Author: kremenek
> Date: Mon May 21 18:29:01 2012
> New Revision: 157219
>
> URL: http://llvm.org/viewvc/llvm-project?rev=157219&view=rev
> Log:
> Add basic delta-debugging script used for reducing analyzer crasher test
> cases.
>
> Added:
>    cfe/trunk/utils/analyzer/reducer.pl   (with props)
>
> Added: cfe/trunk/utils/analyzer/reducer.pl
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/utils/analyzer/reducer.pl?rev=157219&view=auto
>
> ==============================================================================
> --- cfe/trunk/utils/analyzer/reducer.pl (added)
> +++ cfe/trunk/utils/analyzer/reducer.pl Mon May 21 18:29:01 2012
> @@ -0,0 +1,65 @@
> +#!/usr/bin/perl -w
> +use strict;
> +use File::Temp qw/ tempdir /;
> +my $prog = "reducer";
> +
> +die "$prog <code file> <error string> [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 <<ENDTEXT;
>

Escaped perl inside a here-doc is a little too gnarly. I'd rather you used
__DATA__ and read it into a string, then did a series of
s/VARIABLE/$variable/g substitutions on the string to feed in the values.
(Imagine trying to eyeball a missed \ before $ error in the existing code!)


> +#!/usr/bin/perl -w
> +use strict;
> +my \$BAD = 1;
> +my \$GOOD = 0;
> +`rm -f $reduceOut`;
> +my \$command = "$commandStr > $reduceOut 2>&1";
> +system(\$command);
> +open(IN, "$reduceOut") or exit(\$BAD);
>

open(IN, "$command|") or exit(\$BAD);


> +my \$found = 0;
> +while(<IN>) {
> +  if (/$magic/) { exit \$GOOD; }
> +}
> +exit \$BAD;
> +ENDTEXT
> +close(OUT);
> +`chmod +x $scriptFile`;
> +
> +print "$prog: starting reduction\n";
> +sub multidelta {
> +    my $level = shift @_;
>

I really like that you pass -w and say "use strict;" but I'd also like if
you used function prototypes too:

sub multidelta($) {
  my ($level) = @_;

and not using "shift" does a better job of indicating that you aren't
expecting more than one item on @_

Nick


> +    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";
>
> Propchange: cfe/trunk/utils/analyzer/reducer.pl
>
> ------------------------------------------------------------------------------
>    svn:executable = *
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20120521/b6fc1bfd/attachment.html>


More information about the cfe-commits mailing list