Skip to content

Commit

Permalink
Merge branch 'master' of github.com:csmith-project/csmith
Browse files Browse the repository at this point in the history
  • Loading branch information
regehr committed Jun 9, 2011
2 parents 4ca0e8f + 7b46398 commit a776365
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 94 deletions.
8 changes: 8 additions & 0 deletions BUGS_REPORTED.TXT
@@ -1,5 +1,13 @@
===================================================================

05/27/2011 (total 382)
1 gcc crash bug reported by Arthur O'Dwyer
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49206

05/27/2011 (total 381)
1 clang crash bug reported
http://llvm.org/bugs/show_bug.cgi?id=10040

05/26/2011 (total 380)
1 clang wrong code bug reported
http://llvm.org/bugs/show_bug.cgi?id=10028
Expand Down
26 changes: 23 additions & 3 deletions src/Reducer.cpp
Expand Up @@ -106,6 +106,22 @@ Reducer::configure(void)
StringUtils::chop(line);
// make sure the focus var is marked as used var
const Variable* key = VariableSelector::find_var_by_name(line);
if (key == NULL) {
// it's possible an array variable that is not specifically itemized in the
// program that is the focus var. we manually itemize it here
vector<string> strs;
StringUtils::split_string(line, strs, "[]");
const Variable* ary = VariableSelector::find_var_by_name(strs[0]);
assert(ary && ary->isArray);
const ArrayVariable* av = (const ArrayVariable*)ary;
vector<int> indices;
for (size_t k=0; k<av->get_dimension(); k++) {
assert(k + 1 < strs.size());
indices.push_back(StringUtils::str2int(strs[k+1]));
}
av->itemize(indices);
}
key = VariableSelector::find_var_by_name(line);
assert(key);
monitored_var = key;
used_vars.push_back(key->get_named_var());
Expand All @@ -114,9 +130,13 @@ Reducer::configure(void)
getline(conf, line);
StringUtils::chop(line);
// make sure the focus var is marked as used var
const Variable* v = VariableSelector::find_var_by_name(line);
assert(v);
used_vars.push_back(v);
vector<string> vnames;
StringUtils::split_string(line, vnames, ", ");
for (size_t i=0; i<vnames.size(); i++) {
const Variable* v = VariableSelector::find_var_by_name(vnames[i]);
assert(v);
used_vars.push_back(v);
}
}
else if (line.find("drop parameters") == 0) {
getline(conf, line);
Expand Down
4 changes: 0 additions & 4 deletions utah/scripts/john_driver/evaluate_program.pl
Expand Up @@ -696,10 +696,6 @@ ($$$$$$$)
return (-2,"",-1);
}

if (1) {
system "cat $compilerout >> ${VOLATILE_HOME}/compiler_output.txt";
}

if ($VALGRIND_ON_COMPILER) {
open INF, "<$compilerout" or die;
while (my $line = <INF>) {
Expand Down
File renamed without changes.
159 changes: 72 additions & 87 deletions utah/scripts/reduce/c_delta.pl
Expand Up @@ -2,25 +2,41 @@

use strict;

# todo: avoid duplicate tests
# flip the flow of control so delta_step calls a test routine

# todo: find steps creating strings like "longp_20p_21"
# when doing search and replace, how to specify a larger matching context
# for what is actually replaced

# todo: input file should print output separately instead of checksum
# probably do this via command line option?
# if there's a way to match starting at a specified position, use it

# assumption: we're processing code that has been run through 'indent'
# which adds white space around operators and in other places
# do everything with search and replace instead of substr

# goal: completely dismantle a preprocessed csmith output
# do everything with regexes-- need to specify matching parens, brackets, etc.

# todo: need more minimal matching, probably
# build up the regexes programmatically to support multiple replacement options

# hard
# enumerate regrexes so that they're all tried for each position, even
# when an earlier one matches and then fails

# make sure file starts with a blank

# add passes to
# remove digits from numbers to make them smaller
# run indent speculatively
# turn checksum calls into regular printfs
# delete a complete function

# to regexes, add a way to specify border characters that won't be removed

# avoid testing the same thing twice

# avoid mangling strings

# harder
# transform a function to return void
# inline a function call
# sort functions in order to eliminate prototypes
# un-nest nested calls
# un-nest nested calls in expressions
# move arguments and locals to global scope
# remove level of pointer indirection
# remove array dimension
Expand Down Expand Up @@ -61,8 +77,8 @@
#print "$border\n";
#print "$var1\n";
#print "$var2\n";
print "$borderspc\n";
print "$spcborder\n";
#print "$borderspc\n";
#print "$spcborder\n";

my %replace_regexes = (
"\\:\\s*[0-9]+\\s*;" => ";",
Expand Down Expand Up @@ -101,14 +117,18 @@
"\\-" => "",
"\\!" => "",
"\\~" => "",
"=\\s*\{\\s*\}" => "",
"continue" => "",
"return" => "",
"int argc, char \\*argv\\[\\]" => "void",
"int.*?;" => "",
"for" => "",
"if\\s+\\(.*?\\)" => "",
"struct.*?;" => "",
"if" => "",
"break" => "",
"inline" => "",
"printf" => "",
"int\\s*;" => "",
"print_hash_value" => "",
"transparent_crc" => "",
"platform_main_begin" => "",
Expand Down Expand Up @@ -154,9 +174,12 @@ ($$)
return ($p2-$pos);
}

sub read_file ($)
# these are set at startup time and never change
my $cfile;
my $test;

sub read_file ()
{
(my $cfile) = @_;
open INF, "<$cfile" or die;
$prog = "";
while (my $line = <INF>) {
Expand All @@ -167,7 +190,6 @@ ($)

sub write_file ($)
{
(my $cfile) = @_;
open OUTF, ">$cfile" or die;
print OUTF $prog;
close OUTF;
Expand Down Expand Up @@ -243,6 +265,7 @@ ($$)
while (1) {
return 0 if ($pos >= length ($prog));

my $first = substr($prog, 0, $pos);
my $rest = substr($prog, $pos, -1);

if ($method eq "replace_with_1") {
Expand Down Expand Up @@ -275,52 +298,11 @@ ($$)
print "replacing '$del' at $start--$end : ";
return (1, $pos);
}
} elsif ($method eq "replace_regex1") {
foreach my $str (keys %replace_regexes) {
if ($rest =~ /^(?<pref>$borderspc)(?<str>$str)(?<suf>$spcborder)/) {
my $repl = $+{str};
print "replacing '$repl' at $pos : ";
substr ($prog,
$pos + length ($+{pref}),
length ($repl))
= $replace_regexes{$str};
return (1, $pos);
}
}
} elsif ($method eq "replace_regex2") {
foreach my $str (keys %replace_regexes) {
#print "rest = '$rest'\n";
if ($rest =~ /^(?<pref>$borderspc)(?<str>$str)(?<suf>$spcborder)/) {
my $repl = $+{pref}.$+{str};
print "replacing '$repl' at $pos : ";
substr ($prog,
$pos,
length ($repl))
= $replace_regexes{$str};
return (1, $pos);
}
}
} elsif ($method eq "replace_regex3") {
} elsif ($method eq "replace_regex") {
foreach my $str (keys %replace_regexes) {
if ($rest =~ /^(?<pref>$borderspc)(?<str>$str)(?<suf>$spcborder)/) {
my $repl = $+{pref}.$+{str}.$+{suf};
print "replacing '$repl' at $pos : ";
substr ($prog,
$pos,
length ($repl))
= $replace_regexes{$str};
return (1, $pos);
}
}
} elsif ($method eq "replace_regex4") {
foreach my $str (keys %replace_regexes) {
if ($rest =~ /^(?<pref>$borderspc)(?<str>$str)(?<suf>$spcborder)/) {
my $repl = $+{str}.$+{suf};
print "replacing '$repl' at $pos : ";
substr ($prog,
$pos + length ($+{pref}),
length ($repl))
= $replace_regexes{$str};
my $repl = $replace_regexes{$str};
if ($rest =~ s/^$str/$repl/) {
$prog = $first.$rest;
return (1, $pos);
}
}
Expand Down Expand Up @@ -408,22 +390,38 @@ ($)
return ($? >> 8);
}

sub run_test ($) {
(my $test) = @_;
sub run_test () {
my $res = runit "./$test";
return ($res == 0);
}

my %cache = ();
my $cache_hits = 0;

sub cached_test () {
my $result = $cache{$prog};
my $hit;
if (defined($result)) {
$cache_hits++;
print "(hit) ";
$hit = 1;
} else {
write_file ($cfile);
$result = run_test ();
$cache{$prog} = $result;
$hit = 0;
}
return ($result, $hit);
}

# invariant: test always succeeds for $cfile.bak

my %method_worked = ();
my %method_failed = ();
my %cache = ();
my $cache_hits = 0;
my $old_size = 1000000000;

sub main_loop ($$$) {
(my $cfile, my $test, my $method) = @_;
sub delta_pass ($) {
(my $method) = @_;

my $worked = 0;
my $filepos=0;
Expand All @@ -432,25 +430,15 @@ ($$$)
$bad_cnt = 0;

while (1) {
read_file ($cfile);
read_file ();
my $len = length ($prog);
print "[$pass_num $method ($filepos / $len) s:$good_cnt f:$bad_cnt] ";
(my $delete_res, my $newpos) = delta_step ($method, $filepos);
if (!$delete_res) {
print "no more to delete.\n";
return $worked;
}
my $hit = 0;
my $result = $cache{$prog};
if (defined($result)) {
$cache_hits++;
$hit = 1;
print "(hit) ";
} else {
write_file ($cfile);
$result = run_test ($test);
$cache{$prog} = $result;
}
(my $result, my $hit) = cached_test();

if ($result) {
print "success\n";
Expand Down Expand Up @@ -498,10 +486,7 @@ ($$$)
"replace_with_1" => 6,
"replace_with_nothing" => 6,

"replace_regex1" => 7,
"replace_regex2" => 7,
"replace_regex3" => 7,
"replace_regex4" => 7,
"replace_regex" => 7,

);

Expand All @@ -516,14 +501,14 @@ ()
die;
}

my $test = shift @ARGV;
$test = shift @ARGV;
usage if (!defined($test));
if (!(-x $test)) {
print "test script '$test' not found, or not executable\n";
usage();
}

my $cfile = shift @ARGV;
$cfile = shift @ARGV;
usage if (!defined($cfile));
if (!(-e $cfile)) {
print "'$cfile' not found\n";
Expand Down Expand Up @@ -554,7 +539,7 @@ ()
}

print "making sure test succeeds on initial input...\n";
my $res = run_test ($test);
my $res = run_test ();
if (!$res) {
die "test fails!";
}
Expand All @@ -571,7 +556,7 @@ sub bymethod {
while (1) {
my $success = 0;
foreach my $method (sort bymethod keys %methods) {
$success |= main_loop ($cfile, $test, $method);
$success |= delta_pass ($method);
}
$pass_num++;
last if (!$success);
Expand Down

0 comments on commit a776365

Please sign in to comment.