public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "r.dilz at tue dot nl" <gcc-bugzilla@gcc.gnu.org> 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 [thread overview] Message-ID: <bug-94221-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94221 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. It seems that the variables in a type do not get assigned their proper values 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: module pyimp use iso_c_binding type,bind(C) :: container integer(C_INT) :: val = 3 !assignment here is not reliable in gfortran end type container contains type(container) function test() bind(c,name='test') print*,"running test" print*,test%val end function test type(container) function test2() bind(c,name='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 = test() print*,a%val a = 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: 0 Whereas in test2 it should also output 3. Using ifort, I do get the expected result for test2.
next reply other threads:[~2020-03-19 8:23 UTC|newest] Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-03-19 8:23 r.dilz at tue dot nl [this message] 2020-03-19 11:46 ` [Bug fortran/94221] " rguenth at gcc dot gnu.org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-94221-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).