autoconf-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: AC_FC_CHECK_BOUNDS for Fortran array bounds checking.


From: Ralf Wildenhues
Subject: Re: AC_FC_CHECK_BOUNDS for Fortran array bounds checking.
Date: Sat, 5 Mar 2011 09:35:58 +0100
User-agent: Mutt/1.5.20 (2010-08-04)

* Eric Blake wrote on Tue, Mar 01, 2011 at 08:53:02PM CET:
> On 02/27/2011 09:10 AM, Ralf Wildenhues wrote:
> > 
> > here's a first macro to improve Fortran support in Autoconf.
> > It uses Fortran 90 interface declarations, so a F77 version
> > would have to be different (and I'm not quite sure whether
> > this works as well in Fortran 77).  I only have access to a
> > few of the listed compilers, the other flags are taken from
> > manuals only.  I gather fixes will come from users over time.
> > 
> > OK to push?  Eve-Marie, OK to add your name and email to THANKS?
> 
> OK from my end, after addressing a nit.  In fact, since you are much
> more familiar with Fortran than I am, I'm comfortable with you pushing
> all of your recent Fortran patches if you don't get any better review
> within a few days.

Here we go with an updated patch, which I will push in a minute.

I've addressed your nits, omitted the THANKS update for now (pending
feedback from Eve-Marie), added a few more compilers, and reordered and
reformatted the NEWS entry (in the face of other patches to come).
I also documented the Fortran 90 requirement and the cache variable name
in the manual.

A AC_F77_CHECK_BOUNDS macro would be nice eventually.

Thanks,
Ralf

    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.

diff --git a/NEWS b/NEWS
index 3edebd8..0e36b87 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 5fc9ffe..e6ff3ec 100644
--- a/doc/autoconf.texi
+++ b/doc/autoconf.texi
@@ -8248,6 +8248,20 @@ Fortran Compiler
 message).
 @end defmac
 
address@hidden AC_FC_CHECK_BOUNDS (@ovar{action-if-success}, @
+  @dvar{action-if-failure, AC_MSG_FAILURE})
address@hidden
+
+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,
address@hidden 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.
address@hidden defmac
+
 
 @node Go Compiler
 @subsection Go Compiler Characteristics
diff --git a/lib/autoconf/fortran.m4 b/lib/autoconf/fortran.m4
index 30544c4..180fc6d 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 87403a7..4986ee4 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],
address@hidden@: address@hidden@
+       @FC@ @FCFLAGS@ -o $@ address@hidden@ @LIBS@
+
+.SUFFIXES: .f address@hidden@
address@hidden@:
+       @FC@ @FCFLAGS@ -c @FCFLAGS_f@ $<
+
+clean:
+       rm -f address@hidden@ address@hidden@
+]])
+
+cat >configure.ac <<EOF
+AC_INIT
+AC_PROG_FC
+AC_FC_SRCEXT([f])
+AC_FC_CHECK_BOUNDS
+AC_CONFIG_FILES([Makefile])
+AC_OUTPUT
+EOF
+
+AT_DATA([prog.f],
+[[
+      subroutine copy(a,b,n)
+      integer a(:), b(:), n, i
+      do i = 1, n
+         a(i) = b(i)
+      end do
+      end subroutine
+
+      program main
+      integer, parameter :: n = 20
+      integer a(1:n), b(1:n-1), i
+      interface
+         subroutine copy(a,b,n)
+         integer a(:), b(:), i
+         end subroutine
+      end interface
+
+      call copy(a,b,n)
+      end program
+]])
+
+AT_CHECK_AUTOCONF
+AT_CHECK_CONFIGURE
+: "${MAKE=make}"
+AT_CHECK([$MAKE], [], [ignore], [ignore])
+AT_CHECK([./prog || exit 1], [1], [ignore], [ignore])
+AT_CHECK([$MAKE clean], [], [ignore], [ignore])
+
+AT_CLEANUP



reply via email to

[Prev in Thread] Current Thread [Next in Thread]