diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..57872d0 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/vendor/ diff --git a/Dockerfile b/Dockerfile index e7533b5..f682628 100644 --- a/Dockerfile +++ b/Dockerfile @@ -53,8 +53,7 @@ RUN git clone https://github.com/php/php-src -b master --depth 1 && cd php-src \ && export LDFLAGS='-g -fsanitize=address -shared-libasan -Wl,-rpath=/usr/lib/llvm-16/lib/clang/16/lib/linux/' \ \ && make -j100 \ - && make install \ - && cd .. && rm -rf php-src + && make install ADD php.ini /etc/php/php.ini diff --git a/README.md b/README.md index 1d03028..eb25cc4 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,8 @@ Tested on fa218eab4a9b5304afb871a4405546068cb65008 1. Composer: always fails 2. Psalm: always fails 3. MadelineProto: got a single shutdown hang the first time I tried (even with the new closure fixes), then nothing; expecting an assertion crash -4. Infection: used to fail on some older php-src commit, now doesn't, still including it in order to play around with branches +4. Infection (patched): always fails 5. Psalm (unit): hang due to infinite loop in GC 6. php-parser (unit): always fails +7. Psalm (master, unit): always fails +8. Psalm (patched master, unit): always fails diff --git a/bugs/3_madeline.sh b/bugs/3_madeline.sh index fb226d8..1497710 100755 --- a/bugs/3_madeline.sh +++ b/bugs/3_madeline.sh @@ -2,6 +2,8 @@ standalone=$PWD/bugs/wrap_madeline.php +refactor=$PWD/refactor.php + cd /tmp rm -rf jit_test @@ -13,4 +15,6 @@ cd jit_test cp $standalone wrap.php -docker run -v $PWD:/app --rm --privileged -it asan_tests /usr/bin/php -d opcache.blacklist_filename=b.txt -f /app/wrap.php test.php \ No newline at end of file +php $refactor + +docker run -v $PWD:/app --rm --privileged -it asan_tests /usr/bin/php --repeat 2 -d opcache.blacklist_filename=b.txt -f /app/wrap.php test.php \ No newline at end of file diff --git a/bugs/4_infection.sh b/bugs/4_infection.sh index ecd09b1..fa186e0 100755 --- a/bugs/4_infection.sh +++ b/bugs/4_infection.sh @@ -1,9 +1,8 @@ #!/bin/bash -e -#!/bin/bash -e - wrap=$PWD/bugs/wrap.php standalone=$PWD/bugs/infection.php +refactor=$PWD/refactor.php cd /tmp @@ -14,6 +13,8 @@ cd infection composer i --ignore-platform-reqs +php $refactor + cp $standalone . cp $wrap . diff --git a/bugs/7_psalm_master.sh b/bugs/7_psalm_master.sh new file mode 100755 index 0000000..85a6506 --- /dev/null +++ b/bugs/7_psalm_master.sh @@ -0,0 +1,27 @@ +#!/bin/bash -e + +standalone=$PWD/bugs/wrap.php + +cd /tmp + +rm -rf psalm_7 + +git clone https://github.com/nicelocal/psalm -b master psalm_7 +cd psalm_7 +git checkout c7d7b48bdd798b404976054d1b5220082c2f246e + +git branch -D master || true +git branch master +git checkout master + +export PSALM_ALLOW_XDEBUG=1 + +cp $standalone . + +composer i --ignore-platform-reqs + +echo "About to run psalm" + +docker run -v $PWD:/app --rm --privileged -it asan_tests /usr/bin/php --repeat 2 -f /app/wrap.php /app/psalm --no-cache + +echo "OK, no bugs!" \ No newline at end of file diff --git a/bugs/8_psalm_master_refactor.sh b/bugs/8_psalm_master_refactor.sh new file mode 100755 index 0000000..32f6055 --- /dev/null +++ b/bugs/8_psalm_master_refactor.sh @@ -0,0 +1,30 @@ +#!/bin/bash -e + +standalone=$PWD/bugs/wrap.php +refactor=$PWD/refactor.php + +cd /tmp + +rm -rf psalm_8 + +git clone https://github.com/nicelocal/psalm -b master psalm_8 +cd psalm_8 +git checkout c7d7b48bdd798b404976054d1b5220082c2f246e + +git branch -D master || true +git branch master +git checkout master + +export PSALM_ALLOW_XDEBUG=1 + +cp $standalone . + +composer i --ignore-platform-reqs + +echo "About to run psalm" + +php $refactor + +docker run -v $PWD:/app --rm --privileged -it asan_tests /usr/bin/php --repeat 2 -f /app/wrap.php /app/psalm --no-cache + +echo "OK, no bugs!" \ No newline at end of file diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..58ecc80 --- /dev/null +++ b/composer.json @@ -0,0 +1,17 @@ +{ + "name": "daniil/jit_bugs", + "autoload": { + "psr-4": { + "Daniil\\JitBugs\\": "src/" + } + }, + "authors": [ + { + "name": "Daniil Gentili", + "email": "daniil@daniil.it" + } + ], + "require": { + "nikic/php-parser": "^4.17" + } +} diff --git a/composer.lock b/composer.lock new file mode 100644 index 0000000..d4d4468 --- /dev/null +++ b/composer.lock @@ -0,0 +1,75 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", + "This file is @generated automatically" + ], + "content-hash": "d34d57dc247d3a323a479c321530d36a", + "packages": [ + { + "name": "nikic/php-parser", + "version": "v4.17.1", + "source": { + "type": "git", + "url": "https://github.com/nikic/PHP-Parser.git", + "reference": "a6303e50c90c355c7eeee2c4a8b27fe8dc8fef1d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/a6303e50c90c355c7eeee2c4a8b27fe8dc8fef1d", + "reference": "a6303e50c90c355c7eeee2c4a8b27fe8dc8fef1d", + "shasum": "" + }, + "require": { + "ext-tokenizer": "*", + "php": ">=7.0" + }, + "require-dev": { + "ircmaxell/php-yacc": "^0.0.7", + "phpunit/phpunit": "^6.5 || ^7.0 || ^8.0 || ^9.0" + }, + "bin": [ + "bin/php-parse" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.9-dev" + } + }, + "autoload": { + "psr-4": { + "PhpParser\\": "lib/PhpParser" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Nikita Popov" + } + ], + "description": "A PHP parser written in PHP", + "keywords": [ + "parser", + "php" + ], + "support": { + "issues": "https://github.com/nikic/PHP-Parser/issues", + "source": "https://github.com/nikic/PHP-Parser/tree/v4.17.1" + }, + "time": "2023-08-13T19:53:39+00:00" + } + ], + "packages-dev": [], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": [], + "platform-dev": [], + "plugin-api-version": "2.6.0" +} diff --git a/refactor.php b/refactor.php new file mode 100644 index 0000000..ed63032 --- /dev/null +++ b/refactor.php @@ -0,0 +1,46 @@ +create(ParserFactory::PREFER_PHP7); +$finder = new NodeFinder; +$resolver = new NodeTraverser(new NameResolver()); +$printer = new Standard(); + +foreach ($i as [$file]) { + $f = file_get_contents($file); + try { + $parsed = $resolver->traverse($parser->parse($f)); + } catch (\Throwable) { + continue; + } + + foreach ($finder->findInstanceOf($parsed, FunctionLike::class) as $f) { + if ($f instanceof ArrowFunction) continue; + if ($f->stmts === null) continue; + $f->stmts = [new Foreach_( + new Array_([new ArrayItem(new LNumber(0))]), + new Variable('_'), + ['stmts' => $f->stmts] + )]; + } + + file_put_contents($file, $printer->prettyPrintFile($parsed)); +} diff --git a/run.sh b/run.sh index 0f9650f..fc7db55 100755 --- a/run.sh +++ b/run.sh @@ -2,6 +2,8 @@ docker build . -t asan_tests +composer update + for f in bugs/*sh; do echo "!!! About to run $f !!!" $f || echo "!!! Failed to run $f !!!"