This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Patch, Fortran] PR43015 - ICE with -fcheck=bounds and BIND(C)


The following patch is trivial: Normal procedures with character
argument come with a hidden length argument, which can be used with
-fcheck=bounds to check whether the actual argument is smaller than the
dummy argument.

However, BIND(C) procedures do not have any hidden argument; thus
accessing the non-existing argument leads to an ICE. The fix is trivial:
Don't add the check for BIND(C) procedures.

Build and regtested on x86-64-linux.
OK for the trunk?

Tobias
2010-02-10  Tobias Burnus  <burnus@net-b.de>

	PR fortran/43015
	* trans-decl.c (gfc_generate_function_code): Only check
	actual-vs.-dummy character bounds if not bind(C).

2010-02-10  Tobias Burnus  <burnus@net-b.de>

	PR fortran/43015
	* gfortran.dg/bind_c_usage_20.f90: New test.

Index: gcc/fortran/trans-decl.c
===================================================================
--- gcc/fortran/trans-decl.c	(revision 156656)
+++ gcc/fortran/trans-decl.c	(working copy)
@@ -1,5 +1,5 @@
 /* Backend function setup
-   Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
+   Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
    Free Software Foundation, Inc.
    Contributed by Paul Brook
 
@@ -4367,7 +4367,7 @@ gfc_generate_function_code (gfc_namespac
   /* If bounds-checking is enabled, generate code to check passed in actual
      arguments against the expected dummy argument attributes (e.g. string
      lengths).  */
-  if (gfc_option.rtcheck & GFC_RTCHECK_BOUNDS)
+  if ((gfc_option.rtcheck & GFC_RTCHECK_BOUNDS) && !sym->attr.is_bind_c)
     add_argument_checking (&body, sym);
 
   tmp = gfc_trans_code (ns->code);
Index: gcc/testsuite/gfortran.dg/bind_c_usage_20.f90
===================================================================
--- gcc/testsuite/gfortran.dg/bind_c_usage_20.f90	(revision 0)
+++ gcc/testsuite/gfortran.dg/bind_c_usage_20.f90	(revision 0)
@@ -0,0 +1,13 @@
+! { dg-do compile }
+! { dg-options "-fcheck=bounds" }
+!
+! PR fortran/43015
+!
+! Contributed by Dennis Wassel
+!
+SUBROUTINE foo(msg) BIND(C, name = "Foo")
+  USE, INTRINSIC :: iso_c_binding
+  IMPLICIT NONE
+  CHARACTER (KIND=C_CHAR), INTENT (out) :: msg(*) 
+END SUBROUTINE foo
+

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]