From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4234 invoked by alias); 12 Dec 2011 14:51:05 -0000 Received: (qmail 4223 invoked by uid 22791); 12 Dec 2011 14:51:04 -0000 X-SWARE-Spam-Status: No, hits=-2.9 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 12 Dec 2011 14:50:51 +0000 From: "burnus at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/51514] New: [OOP] Wrong code when passing a CLASS to a TYPE Date: Mon, 12 Dec 2011 14:57:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: fortran X-Bugzilla-Keywords: wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: burnus at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 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 X-SW-Source: 2011-12/txt/msg01260.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51514 Bug #: 51514 Summary: [OOP] Wrong code when passing a CLASS to a TYPE Classification: Unclassified Product: gcc Version: 4.7.0 Status: UNCONFIRMED Keywords: wrong-code Severity: normal Priority: P3 Component: fortran AssignedTo: unassigned@gcc.gnu.org ReportedBy: burnus@gcc.gnu.org The following program (subprog_poly_nonpoly_01_pos.f90) of Reinhold Bader's test suite fails with at run time with: ==17368== Invalid read of size 4 ==17368== at 0x400AB4: MAIN__ (subprog_poly_nonpoly_01_pos.f90:21) ==17368== by 0x400BCD: main (subprog_poly_nonpoly_01_pos.f90:16) That's the line: if (xx%i == 3) then The problem is that one passes the CLASS and not the TYPE to the subroutine: subpr (&xx); if (xx._data->i == 3) The first line should have been subpr(&xx._data) It works with the Intel Compiler 12.1. (See also PR 46990.) module mod_subpr implicit none type :: foo integer :: i = 2 end type type, extends(foo) :: foo_1 real :: r(2) end type contains subroutine subpr(x) type(foo) :: x x%i = 3 end subroutine end module program prog use mod_subpr implicit none class(foo), allocatable :: xx allocate(foo_1 :: xx) call subpr(xx) if (xx%i == 3) then write(*,*) 'OK' else write(*,*) 'FAIL' end if end program