gfortran seems to deallocate a pointer which was not allocated or need not be allocated. The program below compiles, but when executed returns the following error message: a.out(8814) malloc: *** error for object 0x1fa2: Non-aligned pointer being freed *** set a breakpoint in malloc_error_break to debug Bus error (Happens for Linux x86 and x86-64 as well as MAC OS X) The code is: program main type :: string character,dimension(:),allocatable :: chars end type string type :: string_container type(string) :: string end type string_container type(string_container), pointer :: ptr call set_ptr (ptr) contains subroutine set_ptr (ptr) type(string_container), pointer, intent(out) :: ptr ptr => null () end subroutine set_ptr end program main
Created attachment 18249 [details] main program for pointer output
CONFIRM. Affects all GCC with pointer intent (4.3/4.4/4.5). For subroutine set_ptr (ptr) type(string_container), pointer, intent(out) :: ptr one shall not deallocate the pointer. The pointer intent is different from a non-pointer intent: set_ptr (struct string_container * & ptr) { if (ptr != 0) { if (ptr->string.chars.data != 0B) { __builtin_free (ptr->string.chars.data); Untested patch: --- trans-decl.c (Revision 150038) +++ trans-decl.c (Arbeitskopie) @@ -2958,6 +3009,7 @@ init_intent_out_dt (gfc_symbol * proc_sy gfc_init_block (&fnblock); for (f = proc_sym->formal; f; f = f->next) if (f->sym && f->sym->attr.intent == INTENT_OUT + && !sym->attr.pointer && f->sym->ts.type == BT_DERIVED) { if (f->sym->ts.derived->attr.alloc_comp) @@ -3708,6 +3760,7 @@ generate_local_decl (gfc_symbol * sym) if (!sym->attr.referenced && sym->ts.type == BT_DERIVED && sym->ts.derived->attr.alloc_comp + && !sym->attr.pointer && ((sym->attr.dummy && sym->attr.intent == INTENT_OUT) || (sym->attr.result && sym != sym->result)))
Subject: Bug 40851 Author: burnus Date: Mon Jul 27 09:32:20 2009 New Revision: 150108 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=150108 Log: 2009-07-26 Tobias Burnus <burnus@net-b.de> PR fortran/40851 * resolve.c (resolve_symbol): Do not initialize pointer * derived-types. * trans-decl.c (init_intent_out_dt): Ditto. (generate_local_decl): No need to set attr.referenced for DT pointers. 2009-07-26 Tobias Burnus <burnus@net-b.de> PR fortran/40851 * gfortran.dg/derived_init_3.f90: New test. Added: trunk/gcc/testsuite/gfortran.dg/derived_init_3.f90 Modified: trunk/gcc/fortran/ChangeLog trunk/gcc/fortran/resolve.c trunk/gcc/fortran/trans-decl.c trunk/gcc/testsuite/ChangeLog
Thanks for the report. FIXED on the trunk (4.5); I will soon backport it to 4.4/4.3. (Workaround: Do not use INTENT for pointers [which is a Fortran 2003 feature].)
Subject: Bug 40851 Author: burnus Date: Wed Jul 29 09:35:15 2009 New Revision: 150203 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=150203 Log: 2009-07-29 Tobias Burnus <burnus@net-b.de> PR fortran/40851 * resolve.c (resolve_symbol): Do not initialize pointer * derived-types. * trans-decl.c (init_intent_out_dt): Ditto. (generate_local_decl): No need to set attr.referenced for DT pointers. 2009-07-29 Tobias Burnus <burnus@net-b.de> PR fortran/40851 * gfortran.dg/derived_init_3.f90: New test. Added: branches/gcc-4_4-branch/gcc/testsuite/gfortran.dg/derived_init_3.f90 Modified: branches/gcc-4_4-branch/gcc/fortran/ChangeLog branches/gcc-4_4-branch/gcc/fortran/resolve.c branches/gcc-4_4-branch/gcc/fortran/trans-decl.c branches/gcc-4_4-branch/gcc/testsuite/ChangeLog
Subject: Bug 40851 Author: burnus Date: Sun Aug 16 20:29:02 2009 New Revision: 150813 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=150813 Log: 2009-08-16 Tobias Burnus <burnus@net-b.de> PR fortran/40851 * resolve.c (resolve_symbol): Do not initialize pointer * derived-types. * trans-decl.c (init_intent_out_dt): Ditto. (generate_local_decl): No need to set attr.referenced for DT pointers. 2009-08-16 Tobias Burnus <burnus@net-b.de> PR fortran/40851 * gfortran.dg/derived_init_3.f90: New test. Modified: branches/gcc-4_3-branch/gcc/fortran/ChangeLog branches/gcc-4_3-branch/gcc/fortran/resolve.c branches/gcc-4_3-branch/gcc/fortran/trans-decl.c branches/gcc-4_3-branch/gcc/testsuite/ChangeLog
FIXED on the 4.3 branch -> Close.
(In reply to comment #7) > FIXED on the 4.3 branch -> Close. Minor nit: the commit to 4.3 didn't add the test case.
Subject: Bug 40851 Author: burnus Date: Sun Aug 23 16:01:11 2009 New Revision: 151034 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=151034 Log: 2009-08-23 Tobias Burnus <burnus@net-b.de> PR fortran/40851 * gfortran.dg/derived_init_3.f90: New test. Added: branches/gcc-4_3-branch/gcc/testsuite/gfortran.dg/derived_init_3.f90 Modified: branches/gcc-4_3-branch/gcc/testsuite/ChangeLog
(In reply to comment #8) > (In reply to comment #7) > > FIXED on the 4.3 branch -> Close. > Minor nit: the commit to 4.3 didn't add the test case. I forgot to do a "svn add" - and I forgot to do a "svn status" to find such problems. It is not corrected.
(In reply to comment #10) > (In reply to comment #8) > > (In reply to comment #7) > > > FIXED on the 4.3 branch -> Close. > > Minor nit: the commit to 4.3 didn't add the test case. > > I forgot to do a "svn add" - and I forgot to do a "svn status" to find such > problems. It is not corrected. Thanks