Skip to content

Commit f2720ac

Browse files
committed
Detect whether the Fortran compiler handles #warning
Some compilers (gfortran) do not print the warning when the include file is found through include paths, which makes the warning useless. We enable the #warning if we detect that the compiler accepts it and prints the warning we expect. Signed-off-by: Joseph Schuchart <[email protected]>
1 parent b7d444e commit f2720ac

4 files changed

+69
-21
lines changed

config/ompi_configure_options.m4

+4
Original file line numberDiff line numberDiff line change
@@ -253,5 +253,9 @@ else
253253
fi
254254
AM_CONDITIONAL(OMPI_OMPIO_SUPPORT, test "$ompi_want_ompio" = "1")
255255

256+
AC_ARG_ENABLE([deprecate-mpif-h],
257+
[AS_HELP_STRING([--enable-deprecate-mpif-h],
258+
[Mark the mpif.h bindings as deprecated (default: enabled)])])
259+
256260
])dnl
257261

config/ompi_fortran_check_warning.m4

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
dnl -*- shell-script -*-
2+
dnl
3+
dnl Copyright (c) 2025 Stony Brook University. All rights reserved.
4+
dnl $COPYRIGHT$
5+
dnl
6+
dnl Additional copyrights may follow
7+
dnl
8+
dnl $HEADER$
9+
dnl
10+
11+
# Check whether the fortran compiler produces a warning when
12+
# it encounters a #warning directive
13+
14+
# OMPI_FORTRAN_CHECK_WARNING([action if found],
15+
# [action if not found])
16+
# ----------------------------------------------------
17+
AC_DEFUN([OMPI_FORTRAN_CHECK_WARNING],[
18+
AS_VAR_PUSHDEF([warning_var], [ompi_cv_fortran_warning])
19+
20+
AC_CACHE_CHECK([if Fortran compiler supports preprocessor warnings], warning_var,
21+
[
22+
# check if the compiler provides a proper #warning
23+
# some compilers (gfortran) do not show the warning if the file is found
24+
# through an include path, so create a temporary directory and include file
25+
OAC_VAR_SCOPE_PUSH(msg, dir)
26+
dir="tmp_includedir_$$"
27+
msg="This is a deprecated file"
28+
AS_MKDIR_P($dir)
29+
echo "#warning $msg" > $dir/deprecated.h
30+
31+
echo "! -*- fortran -*-
32+
program main
33+
implicit none
34+
include 'deprecated.h'
35+
end program main
36+
" > conftest.f
37+
AS_IF([${FC} ${FCFLAGS} -c -I$dir conftest.f 2>conftest.err >conftest.out],
38+
[ # compilation succeeded, check the produced output for the warning
39+
AS_IF([grep "$msg" conftest.err conftest.out >/dev/null 2>/dev/null],
40+
[AS_VAR_SET(warning_var, "yes")],
41+
[AS_VAR_SET(warning_var, "no (missing warning)")],)],
42+
[AS_VAR_SET(warning_var, "no (compilation failed)")])
43+
OPAL_VAR_SCOPE_POP
44+
rm -rf conftest.f conftest.err conftest.out $dir 2>/dev/null >/dev/null
45+
])
46+
AS_VAR_IF(warning_var, [yes], [$1], [$2])
47+
AS_VAR_POPDEF([warning_var])dnl
48+
])
49+

config/ompi_setup_fc.m4

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ dnl Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved.
1616
dnl Copyright (c) 2009-2020 Cisco Systems, Inc. All rights reserved.
1717
dnl Copyright (c) 2015-2020 Research Organization for Information Science
1818
dnl and Technology (RIST). All rights reserved.
19+
dnl Copyright (c) 2025 Stony Brook University. All rights reserved.
1920
dnl $COPYRIGHT$
2021
dnl
2122
dnl Additional copyrights may follow
@@ -43,7 +44,7 @@ AC_DEFUN_ONCE([_OMPI_SETUP_FC_COMPILER],[
4344
# Fortran compilers (excluding the f77 compiler names) from AC's
4445
# default list of compilers and use it here. This is the main
4546
# reason we have an OMPI-ized version of the PROG_FC macro.
46-
AC_PROG_FC([gfortran flang-new f95 fort xlf95 ifort ifc efc pgfortran pgf95 lf95 f90 xlf90 pgf90 epcf90 nagfor nvfortran])
47+
AC_PROG_FC([gfortran flang-new flang f95 fort xlf95 ifort ifc efc pgfortran pgf95 lf95 f90 xlf90 pgf90 epcf90 nagfor nvfortran])
4748
FCFLAGS="$ompi_fcflags_save"
4849
OPAL_VAR_SCOPE_POP
4950
])

config/ompi_setup_mpi_fortran.m4

+14-20
Original file line numberDiff line numberDiff line change
@@ -55,26 +55,6 @@ AC_DEFUN([OMPI_SETUP_MPI_FORTRAN],[
5555
OMPI_FORTRAN_HAVE_F08_ASSUMED_RANK=0
5656
OMPI_FORTRAN_HAVE_PRIVATE=0
5757

58-
AC_MSG_CHECKING([if we should mark mpif.h bindings as deprecated])
59-
AC_ARG_ENABLE([deprecate-mpif-h],
60-
[AS_HELP_STRING([--enable-deprecate-mpif-h],
61-
[Mark the mpif.h bindings as deprecated (default: enabled)])])
62-
if test "x$FC" != "xflang-new"; then
63-
AC_MSG_RESULT([no (only for flang-new)])
64-
OMPI_FORTRAN_DEPRECATE_MPIF_H=""
65-
elif test "$enable_deprecate_mpif_h" = "no"; then
66-
AC_MSG_RESULT([no])
67-
OMPI_FORTRAN_DEPRECATE_MPIF_H=""
68-
else
69-
if test "$enable_deprecate_mpif_h" = "yes"; then
70-
AC_MSG_RESULT([yes])
71-
else
72-
AC_MSG_RESULT([yes (default)])
73-
fi
74-
OMPI_FORTRAN_DEPRECATE_MPIF_H="#warning mpif.h is deprecated since MPI 4.1. Refer to MPI Sec. 19.1.4."
75-
fi
76-
AC_SUBST(OMPI_FORTRAN_DEPRECATE_MPIF_H)
77-
7858
# These macros control symbol names for Fortran/C interoperability
7959
#
8060
OMPI_F08_SUFFIX="_f08"
@@ -397,6 +377,20 @@ end program]])],
397377
[OMPI_FORTRAN_BUILD_SIZEOF=0])
398378
AC_SUBST(OMPI_FORTRAN_BUILD_SIZEOF)
399379

380+
OMPI_FORTRAN_SUPPORTS_WARNING="no"
381+
AS_IF([! test x"$enable_deprecate_mpif_h" = "xno"],
382+
[OMPI_FORTRAN_CHECK_WARNING([OMPI_FORTRAN_SUPPORTS_WARNING="yes"],
383+
[OMPI_FORTRAN_SUPPORTS_WARNING="no"])])
384+
AC_MSG_CHECKING([if we mark mpif.h bindings as deprecated])
385+
AS_IF([test "x$enable_deprecate_mpif_h" = "xyes" && test "$OMPI_FORTRAN_SUPPORTS_WARNING" = "no"],
386+
[AC_MSG_ERROR([Request to mark mpif.h as deprecated but Fortran compiler does not support warning preprocessor directive.])])
387+
AS_IF([test "x$enable_deprecate_mpif_h" != "xno" && test "$OMPI_FORTRAN_SUPPORTS_WARNING" = "yes"],
388+
[OMPI_FORTRAN_DEPRECATE_MPIF_H="#warning mpif.h is deprecated since MPI 4.1. Refer to MPI Sec. 19.1.4."
389+
AC_MSG_RESULT([yes])],
390+
[OMPI_FORTRAN_DEPRECATE_MPIF_H=""
391+
AC_MSG_RESULT([no])])
392+
AC_SUBST(OMPI_FORTRAN_DEPRECATE_MPIF_H)
393+
400394
#--------------------------------------------
401395
# Fortran use mpi or use mpi_f08 MPI bindings
402396
#--------------------------------------------

0 commit comments

Comments
 (0)