From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id B85A0385840C; Mon, 9 Aug 2021 06:30:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B85A0385840C From: "martin.diehl at kuleuven dot be" To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/101824] New: VOLATILE not honored Date: Mon, 09 Aug 2021 06:30:48 +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: 11.1.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: martin.diehl at kuleuven dot be 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: Mon, 09 Aug 2021 06:30:48 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D101824 Bug ID: 101824 Summary: VOLATILE not honored Product: gcc Version: 11.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: fortran Assignee: unassigned at gcc dot gnu.org Reporter: martin.diehl at kuleuven dot be Target Milestone: --- I have a wrapper to C to control a Fortran program with IPC signals: /* c_interface.c */ #include void signalterm_c(void (*handler)(int)){ signal(SIGTERM, handler); } void signalusr1_c(void (*handler)(int)){ signal(SIGUSR1, handler); } ! c_interface.f90 module c_interface implicit none interface subroutine signalterm_C(handler) bind(C) use, intrinsic :: ISO_C_Binding, only: C_FUNPTR type(C_FUNPTR), intent(in), value :: handler end subroutine signalterm_C subroutine signalusr1_C(handler) bind(C) use, intrinsic :: ISO_C_Binding, only: C_FUNPTR type(C_FUNPTR), intent(in), value :: handler end subroutine signalusr1_C end interface end module c_interface ! wait_for_SIGTERM.f90 program wait_for_SIGTERM use, intrinsic :: ISO_C_binding use c_interface implicit none logical, volatile :: & interface_SIGTERM, & ! termination signal interface_SIGUSR1 ! 1. user-defined signal call init do while( .not. interface_SIGTERM) enddo contains subroutine init() call signalterm_c(c_funloc(catchSIGTERM)) call signalusr1_c(c_funloc(catchSIGUSR1)) call interface_setSIGTERM(.false.) call interface_setSIGUSR1(.false.) end subroutine init subroutine catchSIGTERM(signal) bind(C) integer(C_INT), value :: signal print'(a,i0)', ' received signal ',signal call interface_setSIGTERM(.not. interface_SIGTERM) end subroutine catchSIGTERM subroutine catchSIGUSR1(signal) bind(C) integer(C_INT), value :: signal print'(a,i0)', ' received signal ',signal call interface_setSIGUSR1(.not. interface_SIGUSR1) end subroutine catchSIGUSR1 subroutine interface_setSIGTERM(state) logical, intent(in) :: state interface_SIGTERM =3D state print*, 'set SIGTERM to',state end subroutine interface_setSIGTERM subroutine interface_setSIGUSR1(state) logical, intent(in) :: state interface_SIGUSR1 =3D state print*, 'set SIGUSR1 to',state end subroutine interface_setSIGUSR1 end program Compile and run (tested on Linux): gfortran c_interface.c c_interface.f90 wait_for_SIGTERM.f90 -o wait ./wait& kill -SIGUSR1 XXXX kill -SIGUSR1 XXXX kill -SIGTERM XXXX If compiled without optimization flag, the loop exits on SIGTERM (indented behavior). If compiled with `-O3`, it runs forever. This behavior is independent of the VOLATILE attribute. There is a little discussion on https://fortran-lang.discourse.group/t/volatile-needed/1648=