From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8675 invoked by alias); 14 Jan 2015 20:40:14 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 8623 invoked by uid 48); 14 Jan 2015 20:40:06 -0000 From: "paul.richard.thomas at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/64578] [OOP] Seg-fault and ICE with unlimited polymorphic array pointer function Date: Wed, 14 Jan 2015 20:40:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: fortran X-Bugzilla-Version: 5.0 X-Bugzilla-Keywords: ice-on-valid-code, wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: paul.richard.thomas at gmail dot com X-Bugzilla-Status: NEW X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: cc Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2015-01/txt/msg01239.txt.bz2 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64578 paul.richard.thomas at gmail dot com changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |paul.richard.thomas at gmail dot c | |om --- Comment #8 from paul.richard.thomas at gmail dot com --- (In reply to janus from comment #6) > Reduced test case for the ICE: > > print *, associated(return_pointer()) ! ICE > contains > function return_pointer() > class(*), pointer :: return_pointer(:) > end function > end > > ICEs with 4.8, 4.9, trunk. Rejected by 4.7, because class(*) is not > supported. The above ICE is fixed with: Index: /svn/trunk/gcc/fortran/trans-intrinsic.c =================================================================== *** /svn/trunk/gcc/fortran/trans-intrinsic.c (revision 219297) --- /svn/trunk/gcc/fortran/trans-intrinsic.c (working copy) *************** gfc_conv_associated (gfc_se *se, gfc_exp *** 6544,6550 **** --- 6544,6554 ---- arg1se.expr = build_fold_indirect_ref_loc (input_location, arg1se.expr); if (arg1->expr->ts.type == BT_CLASS) + { tmp2 = gfc_class_data_get (arg1se.expr); + if (GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (tmp2))) + tmp2 = gfc_conv_descriptor_data_get (tmp2); + } else tmp2 = arg1se.expr; } such that type foo integer :: i end type logical :: l class(foo), pointer :: ptr(:) print *, associated(return_pointer()) ! ICE print *, associated(return_pointer1()) ! ICE ptr => return_pointer1 () select type (ptr) type is (foo) print *, ptr%i end select contains function return_pointer() class(foo), pointer :: return_pointer(:) return_pointer => NULL() end function function return_pointer1() class(foo), pointer :: return_pointer1(:) allocate (return_pointer1(2), source = foo(99)) end function end does the right thing.... [pault@localhost pr55901]# ./a.out F T 99 99 The runtime segfault remains because the code for the call to return_pointer in the full example is { struct __class__STAR_1_0p ptrtemp.12; struct __class_MAIN___Foo_t class.11; ptrtemp.12 = return_pointer (&class.11); (struct __vtype__STAR *) ptr._vptr = (struct __vtype__STAR *) ptrtemp.12._vptr; ptr._data = ptrtemp.12._data; } ie. bizarrely, none of the fields in class.11 are set. I'll see if I can understand why. Cheers Paul