[Bug libgcc/60939] New: AIX: exceptions not caught when calling function via pointer

lbl2007 at gmx dot net gcc-bugzilla@gcc.gnu.org
Wed Apr 23 12:07:00 GMT 2014


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60939

            Bug ID: 60939
           Summary: AIX: exceptions not caught when calling function via
                    pointer
           Product: gcc
           Version: 4.8.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libgcc
          Assignee: unassigned at gcc dot gnu.org
          Reporter: lbl2007 at gmx dot net

The attached test program throws a std::runtime_error, but the corresponding
catch block is not executed. This only happens under certain circumstances. 
After some testing I found that the following conditions make the error appear:

(1) The function foo() doing the try/catch is in a compilation unit 
    different from main().
(2) foo() is called from main() via a function pointer (pfoo).
(3) pfoo is initialized in a global static constructor in a compilation 
    unit different from main.

To reproduce the error:
  g++ -g -o demo a.cc b.cc
  ./demo
  BEGIN
  terminate called after throwing an instance of 'std::runtime_error'
    what():  TILT
  IOT/Abort trap (core dumped)

Test program (both raw and preprocessed sources are in the attached TAR file):

//////////////////////////////////////////////////// FILE a.cc
#include <stdio.h>
#include <stdexcept>

extern void (*pFoo)();

void foo()
{
   fputs("BEGIN\n",stderr);
   try { throw std::runtime_error("TILT"); }
   catch( const std::runtime_error &e ) { }
   fputs("OK\n",stderr);
}

struct Init { Init() { pFoo = foo; } } init;

//////////////////////////////////////////////////// FILE b.cc
extern void foo();

void (*pFoo)() = 0;

int main( int argc, char *argv[] )
{
   pFoo();
   return 0;
}

//////////////////////////////////////////////////// Version info:
g++ -v
Using built-in specs.
COLLECT_GCC=/common/mringe/gcc482/local/bin/g++
COLLECT_LTO_WRAPPER=/common/mringe/gcc482/local/libexec/gcc/powerpc-ibm-aix6.1.0.0/4.8.2/lto-wrapper
Target: powerpc-ibm-aix6.1.0.0
Configured with: /common/mringe/gcc482/gcc-4.8.2/configure
--prefix=/common/mringe/gcc482/local --with-as=/usr/bin/as
--with-ld=/usr/bin/ld --enable-languages=c,c++
--enable-version-specific-runtime-libs --disable-nls --enable-decimal-float=dpd
--with-gmp=/common/mringe/gcc482/local --with-mpfr=/common/mringe/gcc482/local
--with-mpc=/common/mringe/gcc482/local
--with-local-prefix=/common/mringe/gcc482/local
Thread model: aix
gcc version 4.8.2 (GCC) 

uname -a
AIX srva001 1 6 00F817FA4C00 AIX



More information about the Gcc-bugs mailing list