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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

106 lines
3.1 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>
[flang] Fix problems with constant arrays with lower bounds that are not 1 There were two problems with constant arrays whose lower bound is not 1. First, when folding the arrays, we were creating the folded array to have lower bounds of 1 but, we were not re-adjusting their lower bounds to the declared values. Second, we were not calculating the extents correctly. Both of these problems led to bogus error messages. I fixed the first problem by adjusting the lower bounds in NonPointerInitializationExpr() in Evaluate/check-expression.cpp. I wrote the class ArrayConstantBoundChanger, which is similar to the existing class ScalarConstantExpander. In the process of implementing and testing it, I found a bug that I fixed in ScalarConstantExpander which caused it to infinitely recurse on parenthesized expressions. I also removed the unrelated class ScalarExpansionVisitor, which was not used. I fixed the second problem by changing the formula that calculates upper bounds in in the function ComputeUpperBound() in Evaluate/shape.cpp. I added tests that trigger the bogus error messages mentioned above along with a constant folding tests that uses array operands with shapes that conform but have different bounds. In the process of adding tests, I discovered that tests in Evaluate/folding09.f90 and folding16.f90 were written incorrectly, and I fixed them. This also revealed a bug in contant folding of the intrinsic "lbounds" which I plan to fix in a later change. Differential Revision: https://reviews.llvm.org/D95449
2021-01-27 00:20:57 +08:00
# 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.
if [[ $# < 3 ]]; then
echo "Usage: $0 <fortran-source> <temp test dir> <f18-executable>"
exit 1
fi
src=$1
[[ ! -f $src ]] && echo "File not found: $src" && exit 1
shift
temp=$1
mkdir -p $temp
shift
CMD="$* -fdebug-dump-symbols"
# Check if tests should assume folding is using libpgmath
if [[ $LIBPGMATH ]]; then
CMD="$CMD -DTEST_LIBPGMATH"
echo "Assuming libpgmath support"
else
echo "Not 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