From: Ralf Wildenhues Date: Sat, 5 Mar 2011 06:55:14 +0000 (+0100) Subject: New macro AC_FC_CHECK_BOUNDS to enable Fortran array bounds checking. X-Git-Tag: v2.68b~94 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8476731b831de939182261f9f67fd656cd1242ba;p=thirdparty%2Fautoconf.git New macro AC_FC_CHECK_BOUNDS to enable Fortran array bounds checking. * lib/autoconf/fortran.m4 (AC_FC_CHECK_BOUNDS): New macro. * doc/autoconf.texi (Fortran Compiler): Document it. * tests/fortran.at (AC_FC_CHECK_BOUNDS): New test. * NEWS: Update. Prompted by report from Eve-Marie Devaliere. Signed-off-by: Ralf Wildenhues --- diff --git a/ChangeLog b/ChangeLog index fa0b5f7b..908690b1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2011-03-05 Ralf Wildenhues + + New macro AC_FC_CHECK_BOUNDS to enable Fortran array bounds checking. + * lib/autoconf/fortran.m4 (AC_FC_CHECK_BOUNDS): New macro. + * doc/autoconf.texi (Fortran Compiler): Document it. + * tests/fortran.at (AC_FC_CHECK_BOUNDS): New test. + * NEWS: Update. + Prompted by report from Eve-Marie Devaliere. + 2011-03-04 Ralf Wildenhues Update known compiler switches for Fortran and OpenMP macros. diff --git a/NEWS b/NEWS index 3edebd80..0e36b87c 100644 --- a/NEWS +++ b/NEWS @@ -12,6 +12,10 @@ GNU Autoconf NEWS - User visible changes. - New macro AC_HEADER_CHECK_STDBOOL. +- New and updated macros for Fortran support: + + AC_FC_CHECK_BOUNDS to enable array bounds checking + * Noteworthy changes in release 2.68 (2010-09-22) [stable] Released by Eric Blake, based on git versions 2.67.*. diff --git a/doc/autoconf.texi b/doc/autoconf.texi index 5fc9ffed..e6ff3ecf 100644 --- a/doc/autoconf.texi +++ b/doc/autoconf.texi @@ -8248,6 +8248,20 @@ calls @var{action-if-failure} (defaults to exiting with an error message). @end defmac +@defmac AC_FC_CHECK_BOUNDS (@ovar{action-if-success}, @ + @dvar{action-if-failure, AC_MSG_FAILURE}) +@acindex{FC_CHECK_BOUNDS} + +The @code{AC_FC_CHECK_BOUNDS} macro tries to enable array bounds checking +in the Fortran compiler. If successful, the @var{action-if-success} +is called and any needed flags are added to @code{FCFLAGS}. Otherwise, +@var{action-if-failure} is called, which defaults to failing with an error +message. The macro currently requires Fortran 90 or a newer dialect. + +The result of the macro is cached in the @code{ac_cv_fc_check_bounds} +variable. +@end defmac + @node Go Compiler @subsection Go Compiler Characteristics diff --git a/lib/autoconf/fortran.m4 b/lib/autoconf/fortran.m4 index 30544c40..180fc6db 100644 --- a/lib/autoconf/fortran.m4 +++ b/lib/autoconf/fortran.m4 @@ -1367,3 +1367,82 @@ else fi AC_LANG_POP([Fortran])dnl ])# AC_FC_LINE_LENGTH + + +# AC_FC_CHECK_BOUNDS([ACTION-IF-SUCCESS], [ACTION-IF-FAILURE = FAILURE]) +# ---------------------------------------------------------------------- +# Look for a compiler flag to turn on array bounds checking for the +# Fortran (FC) compiler, and adds it to FCFLAGS. Call +# ACTION-IF-SUCCESS (defaults to nothing) if successful (i.e. can +# compile code using new extension) and ACTION-IF-FAILURE (defaults to +# failing with an error message) if not. (Defined via DEFUN_ONCE to +# prevent flag from being added to FCFLAGS multiple times.) +# +# The known flags are: +# -fcheck=all, -fbounds-check: gfortran +# -fbounds-check: g77, g95 +# -CB, -check bounds: Intel compiler (icc, ecc, ifort) +# -C: Sun/Oracle compiler (f95) +# -C, -qcheck: IBM compiler (xlf) +# -Mbounds: Portland Group compiler +# -C ,-Mbounds: Cray +# -C, -check_bounds: SGI compiler +# -check_bounds, +check=all: HP Fortran +# -C, -Rb -Rc: Absoft (-Rb: array boundaries, -Rc: array conformance) +# --chk e,s -chk (e,s): Lahey +# -C -C=all: NAGWare +# -C, -ffortran-bounds-check: PathScale pathf90 +# -C: f2c +# -BOunds: Open Watcom +AC_DEFUN_ONCE([AC_FC_CHECK_BOUNDS], +[AC_LANG_PUSH([Fortran])dnl +AC_CACHE_CHECK([for Fortran flag to enable array-bounds checking], + [ac_cv_fc_check_bounds], +[ac_cv_fc_check_bounds=unknown +ac_fc_check_bounds_FCFLAGS_save=$FCFLAGS +for ac_flag in -fcheck=bounds -fbounds-check -check_bounds -Mbounds -qcheck \ + '-check bounds' +check=all --check '-Rb -Rc' -CB -C=all -C \ + -ffortran-bounds-check "--chk e,s" "-chk e -chk s" -bounds +do + FCFLAGS="$ac_fc_check_bounds_FCFLAGS_save $ac_flag" + # We should be able to link a correct program. + AC_LINK_IFELSE([AC_LANG_PROGRAM([], [])], + [AC_LINK_IFELSE([[ + subroutine sub(a) + integer a(:) + a(8) = 0 + end subroutine + + program main + integer a(1:7) + interface + subroutine sub(a) + integer a(:) + end subroutine + end interface + + call sub(a) + end program]], + [# If we can run the program, require failure at run time. + # In cross-compiling mode, we rely on the compiler not accepting + # unknown options. + AS_IF([test "$cross_compiling" = yes], + [ac_cv_fc_check_bounds=$ac_flag; break], + [AS_IF([_AC_DO_TOKENS(./conftest$ac_exeext)], + [], + [ac_cv_fc_check_bounds=$ac_flag; break])])])]) +done +rm -f conftest$ac_exeext conftest.err conftest.$ac_objext conftest.$ac_ext +FCFLAGS=$ac_fc_check_bounds_FCFLAGS_save +]) +if test "x$ac_cv_fc_check_bounds" = xunknown; then + m4_default([$2], + [AC_MSG_ERROR([no Fortran flag for bounds checking found], 77)]) +else + if test "x$ac_cv_fc_check_bounds" != xnone; then + FCFLAGS="$FCFLAGS $ac_cv_fc_check_bounds" + fi + $1 +fi +AC_LANG_POP([Fortran])dnl +])# AC_FC_CHECK_BOUNDS diff --git a/tests/fortran.at b/tests/fortran.at index 87403a7e..4986ee48 100644 --- a/tests/fortran.at +++ b/tests/fortran.at @@ -932,3 +932,62 @@ EOF done AT_CLEANUP + + +## ------------------- ## +## AC_FC_CHECK_BOUNDS. ## +## ------------------- ## + +AT_SETUP([AC_FC_CHECK_BOUNDS]) + +AT_DATA([Makefile.in], +[[prog@EXEEXT@: prog.@OBJEXT@ + @FC@ @FCFLAGS@ -o $@ prog.@OBJEXT@ @LIBS@ + +.SUFFIXES: .f .@OBJEXT@ +.f.@OBJEXT@: + @FC@ @FCFLAGS@ -c @FCFLAGS_f@ $< + +clean: + rm -f *.@OBJEXT@ prog@EEXEXT@ +]]) + +cat >configure.ac <