llvm/flang/test/semantics/test_modfile.sh

66 lines
1.9 KiB
Bash
Raw Normal View History

#!/usr/bin/env bash
# Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Compile a source file and compare generated .mod files against expected.
set -e
PATH=/usr/bin:/bin
srcdir=$(dirname $0)
CMD="${F18:-../../../tools/f18/f18} -fdebug-resolve-names -fparse-only"
if [[ $# != 1 ]]; then
echo "Usage: $0 <fortran-source>"
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
( cd $temp && $CMD $src )
actual=$temp/actual.mod
expect=$temp/expect.mod
actual_files=$temp/actual_files
diffs=$temp/diffs
( cd $temp && ls -1 *.mod ) > $actual_files
expected_files=$(sed -n 's/^!Expect: \(.*\)/\1/p' $src)
extra_files=$(echo "$expected_files" | comm -23 $actual_files -)
if [[ ! -z "$extra_files" ]]; then
echo "Unexpected .mod files produced:" $extra_files
echo FAIL
exit 1
fi
for mod in $expected_files; do
if [[ ! -f $temp/$mod ]]; then
echo "Compilation did not produce expected mod file: $mod"
echo FAIL
exit 1
fi
sed '/^!mod\$/d' $temp/$mod > $actual
[flang] Support writing interfaces in module files. Write symbols for external subprogram interfaces as interface-stmts. Those go in the decls part of the module file, as opposed to contained subprograms which go in the contains part. See modfile06.f90. Write symbols with GenericDetails to module files. The specific procedures of a generic interface are always written as procedure-stmts. If they also have specific interfaces those are written in a separate interface-stmt. See modfile07.f90. Fix a bug where `real, external :: f` was not written like `real f; external f`. We have to notice the EXTERNAL attribute on the type-declaration-stmt and convert the entity to a procedure entity. See modfile08.f90. Fix a bug where a use-associated symbol is referenced in a procedure-designator. We were not resolving that correctly. Change ModFileWriter::PutEntity to include the kind of Details when it reports an internal error due to a kind it can't handle. Make DetailsToString public to support that. Change test_errors.sh to fail if the f18 command exits due to a signal. We were missing bugs where the correct errors were written out but then module file writing crashed (due to failure to handle generics mentioned above). Non-zero exit status is okay because we are expecting compilation errors. Change test_modfile.sh to allow for the expected module file contents to be indented so the tests are easier to read. Original-commit: flang-compiler/f18@82a7931e51c63ba21f17261727e1e9dc4167dcc9 Reviewed-on: https://github.com/flang-compiler/f18/pull/132 Tree-same-pre-rewrite: false
2018-07-19 22:28:24 +02:00
sed '1,/^!Expect: '"$mod"'/d' $src | sed -e '/^$/,$d' -e 's/^! *//' > $expect
if ! diff -U999999 $actual $expect > $diffs; then
echo "Module file $mod differs from expected:"
sed '1,2d' $diffs
echo FAIL
exit 1
fi
done
echo PASS