From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 6608E385E824; Thu, 19 Mar 2020 08:23:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6608E385E824 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1584606227; bh=QNeyyJJL2hdf+SU5vZfj/P939nLHYxuQq76t8KqMncs=; h=From:To:Subject:Date:From; b=haU48KAz+hWhMgsq78uo8z5dhd7z+/N/ft9Rl+1mmis7uP87pMnViB4SOlOgOEV8o uuo+i6fiLsoCTwsGbyqmrXJ6UsJ0C8A14TM8efMV9PX2rn5MmksHUeb0Shez+1iRl4 FiB9xNLnblAo7fxKQ3oM/sV6rYvTD96h8MR2cFaE= From: "r.dilz at tue dot nl" To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/94221] New: Explicit assignment in type is ignored in some cases Date: Thu, 19 Mar 2020 08:23:47 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: fortran X-Bugzilla-Version: 9.2.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: r.dilz at tue dot nl X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: 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: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 19 Mar 2020 08:23:47 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D94221 Bug ID: 94221 Summary: Explicit assignment in type is ignored in some cases Product: gcc Version: 9.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: fortran Assignee: unassigned at gcc dot gnu.org Reporter: r.dilz at tue dot nl Target Milestone: --- When working with types, I found some unexpected behavior.=20 It seems that the variables in a type do not get assigned their proper valu= es reliably. I suspect that the compiler does not check well enough whether a variable is used or not and the whole assignment is then optimized away. Below is a minimal example:=20 module pyimp use iso_c_binding type,bind(C) :: container integer(C_INT) :: val =3D 3 !assignment here is not reliable in gfortran end type container contains type(container) function test() bind(c,name=3D'test') print*,"running test" print*,test%val end function test type(container) function test2() bind(c,name=3D'test2') print*,"running test - here test%val is not initialized" end function test2 end module pyimp program main use pyimp type(container) :: a print*,"First: the test%var is initialized by an extra print statement:" a =3D test() print*,a%val a =3D test2() print*,"But in test2 it is not: " print*,a%val end program main Compiled with fortran 4.8 and fortran 9.2.1, both give the same output: First: the test%var is initialized by an extra print statement: running test 3 3 running test - here test%val is not initialized But in test2 it is not:=20 0 Whereas in test2 it should also output 3. Using ifort, I do get the expected result for test2.=