diff --git a/fortran/lammps.f90 b/fortran/lammps.f90 index a018bb7990..8eae2eb1a4 100644 --- a/fortran/lammps.f90 +++ b/fortran/lammps.f90 @@ -1690,7 +1690,6 @@ CONTAINS IF (size_tagint /= 4_c_int) THEN CALL lmp_error(self, LMP_ERROR_ALL + LMP_ERROR_WORLD, & 'Incompatible integer kind in gather_bonds [Fortran API]') - RETURN END IF IF (ALLOCATED(data)) DEALLOCATE(data) size_bigint = lmp_extract_setting(self, 'bigint') @@ -1717,7 +1716,6 @@ CONTAINS IF (size_tagint /= 8_c_int) THEN CALL lmp_error(self, LMP_ERROR_ALL + LMP_ERROR_WORLD, & 'Incompatible integer kind in gather_bonds [Fortran API]') - RETURN END IF nbonds = lmp_extract_global(self, 'nbonds') IF (ALLOCATED(data)) DEALLOCATE(data) @@ -1750,7 +1748,6 @@ CONTAINS CALL lmp_error(self, LMP_ERROR_ALL + LMP_ERROR_WORLD, & 'Unable to create_atoms; your id/image array types are incompatible& & with LAMMPS_SMALLBIG and LAMMPS_SMALLSMALL [Fortran/create_atoms]') - RETURN ! in case exception is caught END IF n = SIZE(type, KIND=c_int) IF (PRESENT(bexpand)) THEN @@ -1769,8 +1766,6 @@ CONTAINS END IF IF (PRESENT(type)) THEN Ctype = C_LOC(type(1)) - ELSE - RETURN ! We shouldn't get here unless exceptions are being caught END IF IF (PRESENT(image)) THEN Cimage = C_LOC(image(1)) @@ -1782,7 +1777,6 @@ CONTAINS ELSE CALL lmp_error(self, LMP_ERROR_ALL + LMP_ERROR_WORLD, & 'the argument "x" to create_atoms is required') - RETURN END IF IF (PRESENT(v)) THEN Cv = C_LOC(v(1)) @@ -2647,11 +2641,11 @@ CONTAINS IF (.NOT. C_ASSOCIATED(ptr)) THEN f_string = '' - RETURN + ELSE + n = INT(c_strlen(ptr), KIND=KIND(n)) + CALL C_F_POINTER(ptr, c_string, [n+1]) + f_string = array2string(c_string, n) END IF - n = INT(c_strlen(ptr), KIND=KIND(n)) - CALL C_F_POINTER(ptr, c_string, [n+1]) - f_string = array2string(c_string, n) END FUNCTION c2f_string ! Copy a known-length or null-terminated array of C characters into a string diff --git a/unittest/fortran/CMakeLists.txt b/unittest/fortran/CMakeLists.txt index 6cdfd5bbc9..f66b333db1 100644 --- a/unittest/fortran/CMakeLists.txt +++ b/unittest/fortran/CMakeLists.txt @@ -14,8 +14,9 @@ if(CMAKE_Fortran_COMPILER) message(STATUS "Skipping Tests for the LAMMPS Fortran Module: cannot identify Fortran compiler") return() endif() - # GNU Fortran 4.8.x on RHEL/CentOS 7.x is not sufficient to compile the Fortran module - if((CMAKE_Fortran_COMPILER_ID STREQUAL "GNU") AND (CMAKE_Fortran_COMPILER_VERSION VERSION_LESS 6.0)) + # GNU Fortran 4.8.x on RHEL/CentOS 7.x is not sufficient to compile the Fortran module. Work around flang being detected as GNU + get_filename_component(_tmp_fc ${CMAKE_Fortran_COMPILER} NAME) + if((CMAKE_Fortran_COMPILER_ID STREQUAL "GNU") AND (CMAKE_Fortran_COMPILER_VERSION VERSION_LESS 6.0) AND NOT (_tmp_fc STREQUAL "flang")) message(FATAL_ERROR "Need GNU Fortran compiler version 6.x or later for unit testing") endif() @@ -36,6 +37,10 @@ if(CMAKE_Fortran_COMPILER) endif() add_library(flammps STATIC ${LAMMPS_FORTRAN_MODULE} keepstuff.f90) + get_filename_component(_tmp_fc ${CMAKE_Fortran_COMPILER} NAME) + if (_tmp_fc STREQUAL "flang") + target_link_libraries(flammps PUBLIC gfortran) + endif() if(MPI_Fortran_HAVE_F90_MODULE) add_executable(test_fortran_create wrap_create.cpp test_fortran_create.f90) diff --git a/unittest/fortran/keepstuff.f90 b/unittest/fortran/keepstuff.f90 index da18d5965e..63184e1006 100644 --- a/unittest/fortran/keepstuff.f90 +++ b/unittest/fortran/keepstuff.f90 @@ -46,7 +46,7 @@ CONTAINS INTERFACE FUNCTION lammps_malloc(size) BIND(C, name='malloc') - IMPORT :: c_ptr, c_size_t + USE, INTRINSIC :: ISO_C_BINDING, ONLY : c_ptr, c_size_t IMPLICIT NONE INTEGER(c_size_t), VALUE :: size TYPE(c_ptr) :: lammps_malloc