This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug other/64711] New: Unconsistency with -fnon-call-exceptions when used along inline and ipa optimizations


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]