llvm-project/flang/test/Evaluate/test_folding.sh

107 lines
3.2 KiB
Bash
Raw Normal View History

#!/usr/bin/env bash
# This script verifies expression folding.
# It compiles a source file with '-fdebug-dump-symbols' and looks for
# parameter declarations to check they have been folded as expected.
# To check folding of an expression EXPR, the fortran program passed to this script
# must contain the following:
# logical, parameter :: test_x = <compare EXPR to expected value>
# This script will test that all parameter with a name starting with "test_" have
# been folded to .true.
# For instance, acos folding can be tested with:
#
# real(4), parameter :: res_acos = acos(0.5_4)
# real(4), parameter :: exp_acos = 1.047
# logical, parameter :: test_acos = abs(res_acos - exp_acos).LE.(0.001_4)
#
# There are two kinds of failure:
# - test_x is folded to .false.. This means the expression was folded
# but the value is not as expected.
# - test_x is not folded (it is neither .true. nor .false.). This means the
# compiler could not fold the expression.
PATH=/usr/bin:/bin
srcdir=$(dirname $0)
F18CC=${F18:-../../../tools/f18/bin/f18}
CMD="$F18CC -fdebug-dump-symbols -fparse-only"
if [[ $# < 1 ]]; then
echo "Usage: $0 <fortran-source> [-pgmath=<true/false>]"
exit 1
fi
src=$srcdir/$1
[[ ! -f $src ]] && echo "File not found: $src" && exit 1
temp=temp-$1
rm -rf $temp
mkdir $temp
[[ $KEEP ]] || trap "rm -rf $temp" EXIT
# Check if tests should assume folding is using libpgmath
if [[ $# > 1 && "$2" = "-pgmath=true" ]]; then
CMD="$CMD -DTEST_LIBPGMATH"
echo "Assuming libpgmath support"
fi
src1=$temp/symbols.log
src2=$temp/all_parameters.log
src3=$temp/tested_parameters.log
src4=$temp/failures.log
messages=$temp/messages.log
actual_warnings=$temp/actwarnings.log
expected_warnings=$temp/expwarnings.log
warning_diffs=$temp/warnings.diff
if ! ( cd $temp; $CMD $src ) > $src1 2> $messages # compile, dumping symbols
then
cat $messages
echo FAIL compilation
exit 1
fi
# Get all PARAMETER declarations
sed -e '/, PARAMETER/!d' -e 's/, PARAMETER.*init:/ /' \
-e 's/^ *//' $src1 > $src2
# Collect test results
sed -e '/^test_/!d' $src2 > $src3
# Check all tests results (keep tests that do not resolve to true)
sed -e '/\.true\._.$/d' $src3 > $src4
#Check warnings
[flang] Merge pull request flang-compiler/f18#539 from flang-compiler/tsk1 Check that procedures of a generic are distinguishable Original-commit: flang-compiler/f18@a24701e313019dbf84179b79e234f92d61de0fa6 Reviewed-on: https://github.com/flang-compiler/f18/pull/539 Due to a conflicting rebase during the linearizing of flang-compiler/f18, this commit squashes a number of other commits: flang-compiler/f18@9b1343af36bd27b110f31dab39c3a18a657a5760 Some cleanup in characteristics.{h,cc} flang-compiler/f18@ddb70e53d2b4e2bba12686e4ac3c26052758fcc3 Merge branch 'master' of github.com:flang-compiler/f18 into tsk1 flang-compiler/f18@d1eef9506610a427f992180f6b59cafe09abb9b9 Merge branch 'master' of github.com:flang-compiler/f18 into tsk1 flang-compiler/f18@24a6d3ffbf4d26d92222b27faa155bb5b3f517f4 Make test_folding.sh stricter in test for warnings flang-compiler/f18@c2c5b640604acceb45823de8cb5716d6921da7d4 Replace SymbolList with SymbolVector flang-compiler/f18@c8499584dff12381c2ce6d4718761cd225b4d97a Add CopyAttrs to copy attributes from Symbol flang-compiler/f18@0573ffd8b2ed5757e06a4fc6d5ffc4401e800c32 Replace cascading detailsIf calls with std::visit flang-compiler/f18@28ec62b3ffeec1d25fde330069b050655bb52a5d Add name to characteristics::DummyArgument flang-compiler/f18@568eaf01145d4ee979423d06f2a65d07222f6841 Add name to CopySymbol() flang-compiler/f18@8c557b09e752da205cd300f63b5ca69806fb2e78 Check that procedures of a generic are distinguishable flang-compiler/f18@50515fd987fd5479567e1b497f6ba93974ffde76 Merge branch 'master' of github.com:flang-compiler/f18 into tsk1 flang-compiler/f18@a7963e98a4aedc97784b99903d04cdc48fd4c346 Address review comments flang-compiler/f18@edd65b3962dbaa1121c166d47c90730e39c25a04 Merge branch 'master' of github.com:flang-compiler/f18 into tsk1
2019-07-03 05:00:44 +08:00
sed -n 's=^[^:]*:\([0-9]*\):[0-9]*: =\1: =p' $messages > $actual_warnings
awk '
BEGIN { FS = "!WARN: "; }
/^ *!WARN: / { warnings[nwarnings++] = $2; next; }
{ for (i = 0; i < nwarnings; ++i) printf "%d: %s\n", NR, warnings[i]; nwarnings = 0; }
' $src > $expected_warnings
diff -U0 $actual_warnings $expected_warnings > $warning_diffs
if [ -s $src4 ] || [ -s $warning_diffs ]; then
echo "folding test failed:"
# Print failed tests (It will actually print all parameters
# that have the same suffix as the failed test so that one can get more info
# by declaring expected_x and result_x for instance)
if [[ -s $src4 ]]; then
sed -e 's/test_/_/' -e 's/ .*//' $src4 | grep -f - $src2
fi
if [[ -s $warning_diffs ]]; then
echo "$cmd"
< $warning_diffs \
sed -n -e 's/^-\([0-9]\)/actual at \1/p' -e 's/^+\([0-9]\)/expect at \1/p' \
| sort -n -k 2
fi
echo FAIL
exit 1
else
passed_results=$(wc -l < $src3)
passed_warnings=$(wc -l < $expected_warnings)
passed=$(($passed_warnings + $passed_results))
echo all $passed tests passed
echo PASS
fi