Bug 33020

Summary: Bind(C): c_f_pointer: type/rank mismatch error with integer(8) SHAPE
Product: gcc Reporter: Tobias Burnus <burnus>
Component: fortranAssignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED FIXED    
Severity: normal CC: crickett, gcc-bugs
Priority: P3    
Version: 4.3.0   
Target Milestone: ---   
Host: Target:
Build: Known to work:
Known to fail: Last reconfirmed: 2007-08-09 23:04:19
Bug Depends on:    
Bug Blocks: 32630    

Description Tobias Burnus 2007-08-08 06:50:16 UTC
http://www.lrz-muenchen.de/services/software/mathematik/gsl/fortran/index.html

This program (./configure --f90 gfortran) fails to compile with the message:

       call c_f_pointer(pdata,fgsl_permutation_data,(/size/))
                                                   1
Error: Type/rank mismatch in argument 'shape' at (1)


I failed to create a smaller example. The program compiles with g95 and ifort without problems, but it fails with the same error message with NAG f95. For a reduced example, it still fails with NAG f95 but not with gfortran.

I could not see anything which indicated that this program is invalid.
Comment 1 Tobias Burnus 2007-08-08 14:23:13 UTC
Some further testing shows:

NAG f95 always wants to have a default kind for SHAPE in c_f_pointer
though the standard allows all kinds.

If I change integer(fgsl_size_t) (fgsl_size_t = c_site_t = 8) into integer(4), the program works with gfortran while integer(8) shows the type/rank mismatch.

Why it works if I create a minimal test case, but not in the full-blown program, I do not understand.
Comment 2 patchapp@dberlin.org 2007-08-09 21:45:42 UTC
Subject: Bug number PR 33020

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-08/msg00604.html
Comment 3 Tobias Burnus 2007-08-22 21:28:22 UTC
Subject: Bug 33020

Author: burnus
Date: Wed Aug 22 21:28:08 2007
New Revision: 127719

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

	PR fortran/33020
	* resolve.c (gfc_iso_c_sub_interface): Remove setting of type and
	kind for optional SHAPE parameter of C_F_POINTER.

2007-08-22  Christopher D. Rickett  <crickett@lanl.gov>

	PR fortran/33020
	* gfortran.dg/c_f_pointer_shape_tests_2.f03: Update test to
	include multiple kinds for SHAPE parameter within a single
	namespace.
	* gfortran.dg/c_f_pointer_shape_tests_2_driver.c: Ditto.
	* gfortran.dg/c_f_pointer_shape_tests_3.f03: New test case.


Added:
    trunk/gcc/testsuite/gfortran.dg/c_f_pointer_shape_tests_3.f03
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/resolve.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gfortran.dg/c_f_pointer_shape_tests_2.f03
    trunk/gcc/testsuite/gfortran.dg/c_f_pointer_shape_tests_2_driver.c

Comment 4 Tobias Burnus 2007-08-22 21:29:38 UTC
FIXED on the trunk.