Last active
August 29, 2015 14:12
-
-
Save rurban/b8b951d03ff22734f05b to your computer and use it in GitHub Desktop.
bisect-alike src-code change fuzzer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
=pod | |
Change every single occurence of PARROT_CANNOT_RETURN_NULL in all .c files (not .h, as | |
those declarations are autogenerated by make headerizer) to the opposite | |
PARROT_CAN_RETURN_NULL declaration. | |
One by one. | |
Should find two gcc problems in parrot, as of commit 3a3d785: | |
1. https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64459 which is a | |
parrot bug. gcc just was the only compiler I tested (clang, msvc) | |
which did the proper optimization. | |
test: ./parrot runtime/parrot/library/parrotlib.pir | |
=> some IO error with exit code > 0 | |
result: | |
src/schedule.c:244 Parrot_cx_check_scheduler(), which had a wrong | |
if (Parrot_cx_check_scheduler(...) == 0) check in core.ops, and consequently | |
this 0 branch was removed by gcc. | |
2. wrong IO output in the extend API. | |
test: prove t/src/extend.t errors | |
This will find the single wrong function returns_null attribute, if | |
it's the only one. 99.9% fails, only one pass. | |
If there are more wrong functions, the opposite approach needs to | |
done. Disable all returns_null and enable it one-by-one until it | |
fails. | |
=cut | |
use strict; | |
my @lines=`git grep -n ^PARROT_CANNOT_RETURN_NULL src compilers | grep .[cy]:`; | |
# @lines = @lines[470..$#lines]; | |
system "perl Configure.pl --silent 2>/dev/null >/dev/null" and warn "failed to execute: Configure.pl $?\n"; | |
sleep 1.0; | |
for (@lines) { | |
chomp; | |
my ($file, $line) = m/^(.+):(\d+):PARROT_CANNOT_RETURN_NULL/; | |
print "\n$file:$line "; | |
system "git checkout $file"; | |
do_patch($file, $line); | |
do_test(); | |
print $? ? "fail $?\n" : "pass\n"; | |
system "git checkout $file"; | |
unlink "parrot"; | |
} | |
sub do_test { | |
system "make -s headerizer >/dev/null 2>/dev/null"; | |
system "make -s -j4 parrot >/dev/null 2>/dev/null" and warn "error make parrot: $?\n"; | |
sleep 0.1; | |
system "./parrot -o runtime/parrot/include/parrotlib.pbc runtime/parrot/library/parrotlib.pir"; | |
#system "prove -Q t/src/extend.t 2>/dev/null"; | |
} | |
sub do_patch { | |
my ($file, $line) = @_; | |
open my $in, "<", $file or die $!; | |
open my $out, ">", $file.".tmp" or die $!; | |
while (<$in>) { | |
if ($line == $.) { | |
s{PARROT_CANNOT_RETURN_NULL}{PARROT_CAN_RETURN_NULL}; | |
} | |
print $out $_; | |
} | |
close $in; | |
close $out; | |
sleep 0.03; | |
system "mv $file.tmp $file"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment