From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6794 invoked by alias); 21 Jan 2015 15:06:59 -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 6753 invoked by uid 48); 21 Jan 2015 15:06:48 -0000 From: "jbellon at bsc dot es" To: gcc-bugs@gcc.gnu.org Subject: [Bug other/64711] New: Unconsistency with -fnon-call-exceptions when used along inline and ipa optimizations Date: Wed, 21 Jan 2015 15:06:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: other X-Bugzilla-Version: 4.8.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: jbellon at bsc dot es X-Bugzilla-Status: UNCONFIRMED 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 attachments.created Message-ID: 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/msg02218.txt.bz2 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64711 Bug ID: 64711 Summary: Unconsistency with -fnon-call-exceptions when used along inline and ipa optimizations Product: gcc Version: 4.8.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: other Assignee: unassigned at gcc dot gnu.org Reporter: jbellon at bsc dot es Created attachment 34517 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=34517&action=edit Test program source code Behavior of -fnon-call-exceptions mechanism (throwing an exception inside a signal handler) is not consistent if optimization options change, that is, the result of a given program can be different. In order to make a comparison, I ran a test program several times, each with different optimizations enabled. The test consists on copying a buffer (r/w protected) content to another (will trigger a SIGSEGV signal). The program uses two additional functions that make a call to another as shown below: main --> foo --> copy --> std::copy (raises SIGSEGV) --> handler Each of the function calls are surounded by a try/catch block. 1) Compilation either with -O0 or without any flags (just -fnon-call-exceptions): Exception is caught at the "copy" function (the one which calls std::copy). This is the expected behavior. 2) Compilation using -O1 -O2 or -O3 flag directly: Exception is not being caught. 3) If both -fno-inline and -fno-ipa-pure-const are included before -OX, then the program behaves as in (1): CXXFLAGS=-fnon-call-exceptions -fno-inline -fno-ipa-pure-const -O1 4) Compilation using both -finline -fipa-pure-const, but without any other optimization: Exception is caught in "foo" function. 5) Compilation using -fipa-pure-const only Same as (3). 6) Compilation using -finline only Same as (1). 7) Compilation using -fipa-pure-const -finline -finline-functions Same as (3). 8) Compilation using -fno-inline -O1 Same as (2). 9) Compilation using -fno-ipa-pure-const -O1 Same as (3). It seems that catch blocks are being optimized out or that, because of the inlining, the generated code is not able to find any catch blocks inside its scope. The test program is attached. Compile command used is: g++ -fnon-call-exceptions [-fno-ipa-pure-const -fno-inline] -O{0,1,2,3} file.cpp -o exec or g++ -fnon-call-exceptions -fipa-pure-const -finline file.cpp -o exec -------------------------- System info GCC version: g++ (SUSE Linux) 4.8.1 20130909 [gcc-4_8-branch revision 202388] Also reproduced with (default flags) public SVN versions: g++ (GCC) 4.8.1 g++ (GCC) 5.0.0 20150109 (experimental) Linux version (openSUSE 13.1) Linux 3.11.10-25-desktop #1 SMP PREEMPT Wed Dec 17 17:57:03 UTC 2014 (8210f77) x86_64 GNU/Linux