Bug 33760 - Bind(C): Using C_PTR as structure constructor gives an ICE
Summary: Bind(C): Using C_PTR as structure constructor gives an ICE
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.3.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: ice-on-invalid-code
Depends on:
Blocks:
 
Reported: 2007-10-13 11:04 UTC by Tobias Burnus
Modified: 2007-10-17 06:57 UTC (History)
2 users (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-10-13 11:04:57 UTC
gfortran crashes if one uses

   cptr = C_PTR(p+1)

Here, C_PTR is a structure constructor; this usage is invalid Fortran 2003 (as type(C_PTR) has PRIVATE components according to the Fortran 2003 standard); NAG f95 therefore diagnoses:
  Error: Components of structure constructor 'c_ptr' at (1) are PRIVATE

gfortran allows currently to access the private components to allow to print the pointer address as in
  print *, cptr
(For -std=f2003, this gives the expected error because of the private components. However, for C_PTR(..) -std=f2003 does not help.)

Valgrind:
==15961== Invalid read of size 8
==15961==    at 0x49F466: gfc_conv_expr (trans-expr.c:3316)
==15961==    by 0x49FB9C: gfc_trans_assignment_1 (trans-expr.c:4075)
==15961==    by 0x49FDAC: gfc_trans_assignment (trans-expr.c:4222)
==15961==    by 0x482E67: gfc_trans_code (trans.c:993)
==15961==    by 0x498669: gfc_generate_function_code (trans-decl.c:3307)
==15961==    by 0x45462B: gfc_parse_file (parse.c:3384)

Test program, found at
http://groups.google.com/group/comp.lang.fortran/browse_thread/thread/0ea1d42c43b6d54a/

program main
   use ISO_C_BINDING
   implicit none
   integer(C_INTPTR_T) p
   type(C_PTR) cptr
   p = 0
   cptr = C_PTR(p+1)
end program main
Comment 1 patchapp@dberlin.org 2007-10-17 04:01:03 UTC
Subject: Bug number PR 33760

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-10/msg00925.html
Comment 2 Tobias Burnus 2007-10-17 06:57:21 UTC
Subject: Bug 33760

Author: burnus
Date: Wed Oct 17 06:57:06 2007
New Revision: 129402

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

        PR fortran/33760
        * symbol.c (gen_special_c_interop_ptr): Remove code to create
        constructor for c_null_ptr and c_null_funptr with value of 0.
        * expr.c (check_init_expr): Prevent check on constructors for
        iso_c_binding derived types.
        * resolve.c (resolve_structure_cons): Verify that the user isn't
        trying to invoke a structure constructor for one of the
        iso_c_binding derived types.


2007-10-17 Christopher D. Rickett <crickett@lanl.gov>

        PR fortran/33760
        * gfortran.dg/c_ptr_tests_13.f03: New test case.


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

Comment 3 Tobias Burnus 2007-10-17 06:57:43 UTC
FIXED on the trunk (4.3.0).