<div class="gmail_quote">On 21 May 2012 16:29, Ted Kremenek <span dir="ltr"><<a href="mailto:kremenek@apple.com" target="_blank">kremenek@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

Author: kremenek<br>
Date: Mon May 21 18:29:01 2012<br>
New Revision: 157219<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=157219&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=157219&view=rev</a><br>
Log:<br>
Add basic delta-debugging script used for reducing analyzer crasher test cases.<br>
<br>
Added:<br>
    cfe/trunk/utils/analyzer/<a href="http://reducer.pl" target="_blank">reducer.pl</a>   (with props)<br>
<br>
Added: cfe/trunk/utils/analyzer/<a href="http://reducer.pl" target="_blank">reducer.pl</a><br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/utils/analyzer/reducer.pl?rev=157219&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/utils/analyzer/reducer.pl?rev=157219&view=auto</a><br>


==============================================================================<br>
--- cfe/trunk/utils/analyzer/<a href="http://reducer.pl" target="_blank">reducer.pl</a> (added)<br>
+++ cfe/trunk/utils/analyzer/<a href="http://reducer.pl" target="_blank">reducer.pl</a> Mon May 21 18:29:01 2012<br>
@@ -0,0 +1,65 @@<br>
+#!/usr/bin/perl -w<br>
+use strict;<br>
+use File::Temp qw/ tempdir /;<br>
+my $prog = "reducer";<br>
+<br>
+die "$prog <code file> <error string> [optional command]\n" if ($#ARGV < 0);<br>
+my $file = shift @ARGV;<br>
+die "$prog: [error] cannot read file $file\n" if (! -r $file);<br>
+<br>
+my $magic = shift @ARGV;<br>
+die "$prog: [error] no error string specified\n" if (! defined $magic);<br>
+<br>
+# Create a backup of the fuke.<br>
+my $dir = tempdir( CLEANUP => 1 );<br>
+print "$prog: created temporary directory '$dir'\n";<br>
+my $srcFile = "$dir/$file";<br>
+`cp $file $srcFile`;<br>
+<br>
+# Create the script.<br>
+my $scriptFile = "$dir/script";<br>
+open(OUT, ">$scriptFile") or die "$prog: cannot create '$scriptFile'\n";<br>
+my $reduceOut = "$dir/reduceOut";<br>
+<br>
+my $command;<br>
+if (scalar(@ARGV) > 0) { $command = \@ARGV; }<br>
+else {<br>
+  my $compiler = "/Users/kremenek/llvm-cmake-release/bin/clang";<br>
+  $command = [$compiler, "-fsyntax-only", "-Wfatal-errors", "-Wno-deprecated-declarations", "-Wimplicit-function-declaration"];<br>
+}<br>
+push @$command, $srcFile;<br>
+my $commandStr = "@$command";<br>
+<br>
+print OUT <<ENDTEXT;<br></blockquote><div><br></div><div>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!)</div>

<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+#!/usr/bin/perl -w<br>
+use strict;<br>
+my \$BAD = 1;<br>
+my \$GOOD = 0;<br>
+`rm -f $reduceOut`;<br>
+my \$command = "$commandStr > $reduceOut 2>&1";<br>
+system(\$command);<br>
+open(IN, "$reduceOut") or exit(\$BAD);<br></blockquote><div><br></div><div>open(IN, "$command|") or exit(\$BAD);</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">


+my \$found = 0;<br>
+while(<IN>) {<br>
+  if (/$magic/) { exit \$GOOD; }<br>
+}<br>
+exit \$BAD;<br>
+ENDTEXT<br>
+close(OUT);<br>
+`chmod +x $scriptFile`;<br>
+<br>
+print "$prog: starting reduction\n";<br>
+sub multidelta {<br>
+    my $level = shift @_;<br></blockquote><div><br></div><div>I really like that you pass -w and say "use strict;" but I'd also like if you used function prototypes too:</div><div><br></div><div>sub multidelta($) {</div>

<div>  my ($level) = @_;</div><div><br></div><div>and not using "shift" does a better job of indicating that you aren't expecting more than one item on @_</div><div><br></div><div>Nick</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">


+    system("multidelta -level=$level $scriptFile $srcFile");<br>
+}<br>
+<br>
+for (my $i = 1 ; $i <= 5; $i++) {<br>
+  foreach my $level (0,0,1,1,2,2,10) {<br>
+    multidelta($level);<br>
+  }<br>
+}<br>
+<br>
+# Copy the final file.<br>
+`cp $srcFile $file.reduced`;<br>
+print "$prog: generated '$file.reduced";<br>
<br>
Propchange: cfe/trunk/utils/analyzer/<a href="http://reducer.pl" target="_blank">reducer.pl</a><br>
------------------------------------------------------------------------------<br>
    svn:executable = *<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
</blockquote></div><br>