User account creation filtered due to spam.

Bug 32804 - ISO C Binding: C_LOC argument checking needs improvement
Summary: ISO C Binding: C_LOC argument checking needs improvement
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.3.0
: P3 normal
Target Milestone: 4.3.0
Assignee: Not yet assigned to anyone
URL:
Keywords: accepts-invalid, rejects-valid
Depends on:
Blocks: 32630
  Show dependency treegraph
 
Reported: 2007-07-18 07:47 UTC by Tobias Burnus
Modified: 2007-07-21 20:36 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Burnus 2007-07-18 07:47:44 UTC
subroutine aaa(in)
      use iso_c_binding
      implicit none
      CHARACTER(KIND=C_CHAR), DIMENSION(*), TARGET  :: in
      type(c_ptr) :: cptr
      cptr = c_loc(in)
      end subroutine

Wrongly rejected with:
  Error: CHARACTER argument 'in' to 'c_loc' at (1) must have a length of 1

      subroutine aaa(in)
      use iso_c_binding
      implicit none
      integer(KIND=C_int), DIMENSION(:), TARGET  :: in
      type(c_ptr) :: cptr
      cptr = c_loc(in)
      end subroutine

Wrongly accepts this; NAG f95 writes:

Error: aa.f90, line 6: The argument to C_LOC must not be an assumed-shape array
Comment 1 Tobias Burnus 2007-07-19 08:30:57 UTC
For the accept-invalid part (c_loc of an assumed-shape array). The standard says:
"X shall either
 (1) have interoperable type and type parameters and be
   (a) a variable that has the TARGET attribute and is interoperable,"

This variable has the TARGET attribute, but is not interoperable:
"An array Fortran variable is interoperable if its type and type parameters are interoperable and it is of explicit shape or assumed size."

Thus this error by NAG f95 is ok; however, as it is accepted by ifort, g95 and (currently) gfortran. As I completely fail to see any valid use of it and see several cases where it seems to work but one uses in reality the wrong array element, I favour to not allowing it even for -std=gnu. But if one finds a valid use, I'm also fine with an error only for -std=f2003.
Comment 2 patchapp@dberlin.org 2007-07-19 19:15:15 UTC
Subject: Bug number PR 32804

A patch for this bug has been added to the patch tracker.
The mailing list url for the patch is http://gcc.gnu.org/ml/gcc-patches/2007-07/msg01577.html
Comment 3 kargl 2007-07-21 20:31:38 UTC
Subject: Bug 32804

Author: kargl
Date: Sat Jul 21 20:31:17 2007
New Revision: 126812

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=126812
Log:
2007-07-21  Christopher D. Rickett  <crickett@lanl.gov>

        PR fortran/32801
        * symbol.c (generate_isocbinding_symbol): Remove unnecessary
        conditional.

        PR fortran/32804
        * resolve.c (gfc_iso_c_func_interface): Reject assumed-shape and
        deferred-shape arrays as args to C_LOC.  Fix bug in testing
        character args to C_LOC.

2007-07-21  Christopher D. Rickett  <crickett@lanl.gov>

        PR fortran/32804
        * gfortran.dg/c_loc_tests_9.f03: New test case.
        * gfortran.dg/c_loc_tests_10.f03: Ditto.


Added:
    trunk/gcc/testsuite/gfortran.dg/c_loc_tests_10.f03
    trunk/gcc/testsuite/gfortran.dg/c_loc_tests_9.f03
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/resolve.c
    trunk/gcc/fortran/symbol.c
    trunk/gcc/testsuite/ChangeLog

Comment 4 kargl 2007-07-21 20:36:58 UTC
Fixed on trunk.