diff --git a/flang/CMakeLists.txt b/flang/CMakeLists.txt index ac30da89995ed..f81d3e33fe86c 100644 --- a/flang/CMakeLists.txt +++ b/flang/CMakeLists.txt @@ -276,6 +276,9 @@ endif() set(PACKAGE_VERSION "${LLVM_PACKAGE_VERSION}") +if (NOT PACKAGE_VERSION) + set(PACKAGE_VERSION ${LLVM_VERSION_MAJOR}) +endif() if (NOT DEFINED FLANG_VERSION_MAJOR) @@ -490,3 +493,17 @@ if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) PATTERN "*.inc" ) endif() + +# Put ISO_Fortran_binding.h into the include files of the build area now +# so that we can run tests before installing +include(GetClangResourceDir) +get_clang_resource_dir(HEADER_BINARY_DIR PREFIX ${LLVM_LIBRARY_OUTPUT_INTDIR}/.. SUBDIR include) +configure_file( + ${FLANG_SOURCE_DIR}/include/flang/ISO_Fortran_binding.h + ${HEADER_BINARY_DIR}/ISO_Fortran_binding.h) + +# And also install it into the install area +get_clang_resource_dir(HEADER_INSTALL_DIR SUBDIR include) +install( + FILES include/flang/ISO_Fortran_binding.h + DESTINATION ${HEADER_INSTALL_DIR} ) diff --git a/flang/test/Driver/ctofortran.f90 b/flang/test/Driver/ctofortran.f90 new file mode 100644 index 0000000000000..6483e0deb3866 --- /dev/null +++ b/flang/test/Driver/ctofortran.f90 @@ -0,0 +1,73 @@ +! UNSUPPORTED: system-windows +! RUN: split-file %s %t +! RUN: chmod +x %t/runtest.sh +! RUN: %t/runtest.sh %t %flang $t/ffile.f90 $t/cfile.c + +!--- ffile.f90 +subroutine foo(a) bind(c) + integer :: a(:) + if (lbound(a, 1) .ne. 1) then + print *, 'FAIL expected 1 for lbound but got ',lbound(a, 1) + stop 1 + endif + + if (ubound(a, 1) .ne. 10) then + print *, 'FAIL expected 10 for ubound but got ',ubound(a, 1) + stop 1 + endif + + do i = lbound(a,1),ubound(a,1) + !print *, a(i) + if (a(i) .ne. i) then + print *, 'FAIL expected', i, ' for index ',i, ' but got ',a(i) + stop 1 + endif + enddo + print *, 'PASS' +end subroutine foo + +! CHECK: PASS +!--- cfile.c +#include +#include +#include + +void foo(CFI_cdesc_t*); + +int a[10]; + +int main() { + int i, res; + static CFI_CDESC_T(1) r1; + CFI_cdesc_t *desc = (CFI_cdesc_t*)&r1; + CFI_index_t extent[1] = {10}; + + for(i=0; i<10; ++i) { + a[i] = i+1; + } + + res = CFI_establish(desc, (void*)a, CFI_attribute_other, CFI_type_int32_t, + sizeof(int), 1, extent); + if (res != 0) { + printf("FAIL CFI_establish returned %d instead of 0.\n",res); + exit(1); + } + + foo(desc); + return 0; +} +!--- runtest.sh +#!/bin/bash +export BINDIR=`dirname $2` +export CCOMP=$BINDIR/clang +if [ -x $CCOMP ] +then + export LIBDIR=$BINDIR/../lib + export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$LIBDIR + $CCOMP -c $1/$4 -o $1/cfile.o + $2 $1/$3 $1/cfile.o -o $1/ctofortran + $1/ctofortran # should print "PASS" +else + # No clang compiler, just pass by default + echo "PASS" +fi