From 3bf418bdf9ae0e292afe5becb661ff9b441aa168 Mon Sep 17 00:00:00 2001 From: geoffk Date: Fri, 24 Feb 2006 21:43:01 +0000 Subject: [PATCH] Index: gcc/ChangeLog 2006-02-24 Geoffrey Keating * doc/tm.texi (Run-time Target): Document C_COMMON_OVERRIDE_OPTIONS. * doc/invoke.texi (C++ Dialect Options): Document -fno-use-cxa-get-exception-ptr. * configure.ac: Define DEFAULT_USE_CXA_ATEXIT to 2 not 1. * configure: Regenerate. * c.opt (fuse-cxa-get-exception-ptr): New. * c-opts.c (c_common_handle_option): Handle OPT_fuse_cxa_get_exception_ptr. * c-common.c (flag_use_cxa_atexit): Update documentation. (flag_use_cxa_get_exception_ptr): New. * c-common.h (flag_use_cxa_get_exception_ptr): New. * config/rs6000/darwin.h (SUBTARGET_OVERRIDE_OPTIONS): Improve documentation. (C_COMMON_OVERRIDE_OPTIONS): New. Index: gcc/testsuite/ChangeLog 2006-02-24 Geoffrey Keating * g++.dg/eh/uncaught1.C: Add dg-options for ppc-darwin. * g++.dg/eh/uncaught2.C: New. * g++.dg/eh/uncaught3.C: New. Index: gcc/cp/ChangeLog 2006-02-24 Geoffrey Keating * except.c (expand_start_catch_block): Handle flag_use_cxa_get_exception_ptr. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@111427 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/ChangeLog | 17 ++++++++ gcc/c-common.c | 8 +++- gcc/c-common.h | 5 +++ gcc/c-opts.c | 10 +++++ gcc/c.opt | 4 ++ gcc/config/rs6000/darwin.h | 20 +++++++-- gcc/configure | 2 +- gcc/configure.ac | 2 +- gcc/cp/ChangeLog | 5 +++ gcc/cp/except.c | 3 +- gcc/doc/invoke.texi | 6 +++ gcc/doc/tm.texi | 7 ++++ gcc/testsuite/ChangeLog | 6 +++ gcc/testsuite/g++.dg/eh/uncaught1.C | 1 + gcc/testsuite/g++.dg/eh/uncaught2.C | 84 +++++++++++++++++++++++++++++++++++++ gcc/testsuite/g++.dg/eh/uncaught3.C | 84 +++++++++++++++++++++++++++++++++++++ 16 files changed, 257 insertions(+), 7 deletions(-) create mode 100644 gcc/testsuite/g++.dg/eh/uncaught2.C create mode 100644 gcc/testsuite/g++.dg/eh/uncaught3.C diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 0fef1ea..d541925 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,20 @@ +2006-02-24 Geoffrey Keating + + * doc/tm.texi (Run-time Target): Document C_COMMON_OVERRIDE_OPTIONS. + * doc/invoke.texi (C++ Dialect Options): Document + -fno-use-cxa-get-exception-ptr. + * configure.ac: Define DEFAULT_USE_CXA_ATEXIT to 2 not 1. + * configure: Regenerate. + * c.opt (fuse-cxa-get-exception-ptr): New. + * c-opts.c (c_common_handle_option): Handle + OPT_fuse_cxa_get_exception_ptr. + * c-common.c (flag_use_cxa_atexit): Update documentation. + (flag_use_cxa_get_exception_ptr): New. + * c-common.h (flag_use_cxa_get_exception_ptr): New. + * config/rs6000/darwin.h (SUBTARGET_OVERRIDE_OPTIONS): Improve + documentation. + (C_COMMON_OVERRIDE_OPTIONS): New. + 2006-02-24 Roger Sayle PR middle-end/24952 diff --git a/gcc/c-common.c b/gcc/c-common.c index 759a68c..4f8ab8e 100644 --- a/gcc/c-common.c +++ b/gcc/c-common.c @@ -424,10 +424,16 @@ int flag_weak = 1; int flag_working_directory = -1; /* Nonzero to use __cxa_atexit, rather than atexit, to register - destructors for local statics and global objects. */ + destructors for local statics and global objects. '2' means it has been + set nonzero as a default, not by a command-line flag. */ int flag_use_cxa_atexit = DEFAULT_USE_CXA_ATEXIT; +/* Nonzero to use __cxa_get_exception_ptr in C++ exception-handling + code. '2' means it has not been set explicitly on the command line. */ + +int flag_use_cxa_get_exception_ptr = 2; + /* Nonzero means make the default pedwarns warnings instead of errors. The value of this flag is ignored if -pedantic is specified. */ diff --git a/gcc/c-common.h b/gcc/c-common.h index 6498255..ed93f97 100644 --- a/gcc/c-common.h +++ b/gcc/c-common.h @@ -549,6 +549,11 @@ extern int flag_working_directory; extern int flag_use_cxa_atexit; +/* Nonzero to use __cxa_get_exception_ptr in the C++ exception-handling + logic. */ + +extern int flag_use_cxa_get_exception_ptr; + /* Nonzero means make the default pedwarns warnings instead of errors. The value of this flag is ignored if -pedantic is specified. */ diff --git a/gcc/c-opts.c b/gcc/c-opts.c index 00a8631..c53238b 100644 --- a/gcc/c-opts.c +++ b/gcc/c-opts.c @@ -786,6 +786,10 @@ c_common_handle_option (size_t scode, const char *arg, int value) flag_use_cxa_atexit = value; break; + case OPT_fuse_cxa_get_exception_ptr: + flag_use_cxa_get_exception_ptr = value; + break; + case OPT_fvisibility_inlines_hidden: visibility_options.inlines_hidden = value; break; @@ -978,6 +982,12 @@ c_common_post_options (const char **pfilename) register_include_chains (parse_in, sysroot, iprefix, imultilib, std_inc, std_cxx_inc && c_dialect_cxx (), verbose); +#ifdef C_COMMON_OVERRIDE_OPTIONS + /* Some machines may reject certain combinations of C + language-specific options. */ + C_COMMON_OVERRIDE_OPTIONS; +#endif + flag_inline_trees = 1; /* Use tree inlining. */ diff --git a/gcc/c.opt b/gcc/c.opt index 8f58d3d..1fd12f7 100644 --- a/gcc/c.opt +++ b/gcc/c.opt @@ -713,6 +713,10 @@ fuse-cxa-atexit C++ ObjC++ Use __cxa_atexit to register destructors +fuse-cxa-get-exception-ptr +C++ ObjC++ +Use __cxa_get_exception_ptr in exception handling + fvisibility-inlines-hidden C++ ObjC++ Marks all inlined methods as having hidden visibility diff --git a/gcc/config/rs6000/darwin.h b/gcc/config/rs6000/darwin.h index 46119c8..30a2fff 100644 --- a/gcc/config/rs6000/darwin.h +++ b/gcc/config/rs6000/darwin.h @@ -59,11 +59,10 @@ while (0) -/* The Darwin ABI always includes AltiVec, can't be (validly) turned - off. */ - #define SUBTARGET_OVERRIDE_OPTIONS \ do { \ + /* The Darwin ABI always includes AltiVec, can't be (validly) turned \ + off. */ \ rs6000_altivec_abi = 1; \ TARGET_ALTIVEC_VRSAVE = 1; \ if (DEFAULT_ABI == ABI_DARWIN) \ @@ -87,6 +86,21 @@ do { \ } \ } while(0) +#define C_COMMON_OVERRIDE_OPTIONS do { \ + /* On powerpc, __cxa_get_exception_ptr is available starting in the \ + 10.5 libstdc++.dylib. */ \ + if ((! darwin_macosx_version_min \ + || strverscmp (darwin_macosx_version_min, "10.5") < 0) \ + && flag_use_cxa_get_exception_ptr == 2) \ + flag_use_cxa_get_exception_ptr = 0; \ + /* On powerpc, __cxa_atexit is available starting in the 10.4 \ + libSystem.dylib. */ \ + if ((! darwin_macosx_version_min \ + || strverscmp (darwin_macosx_version_min, "10.4") < 0) \ + && flag_use_cxa_atexit == 2) \ + flag_use_cxa_atexit = 0; \ +} while (0) + /* Darwin has 128-bit long double support in libc in 10.4 and later. Default to 128-bit long doubles even on earlier platforms for ABI consistency; arithmetic will work even if libc and libm support is diff --git a/gcc/configure b/gcc/configure index b07c286..fe6f1bd 100755 --- a/gcc/configure +++ b/gcc/configure @@ -12346,7 +12346,7 @@ fi if test x$use_cxa_atexit = xyes; then cat >>confdefs.h <<\_ACEOF -#define DEFAULT_USE_CXA_ATEXIT 1 +#define DEFAULT_USE_CXA_ATEXIT 2 _ACEOF fi diff --git a/gcc/configure.ac b/gcc/configure.ac index 1b8feab..447f827 100644 --- a/gcc/configure.ac +++ b/gcc/configure.ac @@ -1392,7 +1392,7 @@ if test x$enable___cxa_atexit = xyes || \ use_cxa_atexit=yes fi if test x$use_cxa_atexit = xyes; then - AC_DEFINE(DEFAULT_USE_CXA_ATEXIT, 1, + AC_DEFINE(DEFAULT_USE_CXA_ATEXIT, 2, [Define if you want to use __cxa_atexit, rather than atexit, to register C++ destructors for local statics and global objects. This is essential for fully standards-compliant handling of diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index c888a09..a1df2bb 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2006-02-24 Geoffrey Keating + + * except.c (expand_start_catch_block): Handle + flag_use_cxa_get_exception_ptr. + 2006-02-22 Volker Reichelt PR c++/26291 diff --git a/gcc/cp/except.c b/gcc/cp/except.c index 8d68486..87e9586 100644 --- a/gcc/cp/except.c +++ b/gcc/cp/except.c @@ -446,7 +446,8 @@ expand_start_catch_block (tree decl) /* If the C++ object needs constructing, we need to do that before calling __cxa_begin_catch, so that std::uncaught_exception gets the right value during the copy constructor. */ - else if (TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (decl))) + else if (flag_use_cxa_get_exception_ptr + && TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (decl))) { exp = do_get_exception_ptr (); initialize_handler_parm (decl, exp); diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 029b43c..a81ab58 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -1581,6 +1581,12 @@ This option is required for fully standards-compliant handling of static destructors, but will only work if your C library supports @code{__cxa_atexit}. +@item -fno-use-cxa-get-exception-ptr +@opindex fno-use-cxa-get-exception-ptr +Don't use the @code{__cxa_get_exception_ptr} runtime routine. This +will cause @code{std::uncaught_exception} to be incorrect, but is necessary +if the runtime routine is not available. + @item -fvisibility-inlines-hidden @opindex fvisibility-inlines-hidden Causes all inlined methods to be marked with diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi index dd57867..cebb71c 100644 --- a/gcc/doc/tm.texi +++ b/gcc/doc/tm.texi @@ -778,6 +778,13 @@ Don't use this macro to turn on various extra optimizations for @option{-O}. That is what @code{OPTIMIZATION_OPTIONS} is for. @end defmac +@defmac C_COMMON_OVERRIDE_OPTIONS +This is similar to @code{OVERRIDE_OPTIONS} but is only used in the C +language frontends (C, Objective-C, C++, Objective-C++) and so can be +used to alter option flag variables which only exist in those +frontends. +@end defmac + @defmac OPTIMIZATION_OPTIONS (@var{level}, @var{size}) Some machines may desire to change what optimizations are performed for various optimization levels. This macro, if defined, is executed once diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index c1d4744..1d4bef3 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2006-02-24 Geoffrey Keating + + * g++.dg/eh/uncaught1.C: Add dg-options for ppc-darwin. + * g++.dg/eh/uncaught2.C: New. + * g++.dg/eh/uncaught3.C: New. + 2006-02-24 Jerry DeLisle PR libgfortran/26423 diff --git a/gcc/testsuite/g++.dg/eh/uncaught1.C b/gcc/testsuite/g++.dg/eh/uncaught1.C index 2aa1068..afbf5af4 100644 --- a/gcc/testsuite/g++.dg/eh/uncaught1.C +++ b/gcc/testsuite/g++.dg/eh/uncaught1.C @@ -1,5 +1,6 @@ // PR libstdc++/10606 // { dg-do run } +// { dg-options "-fuse-cxa-get-exception-ptr" { target powerpc*-*-darwin* } } #include #include diff --git a/gcc/testsuite/g++.dg/eh/uncaught2.C b/gcc/testsuite/g++.dg/eh/uncaught2.C new file mode 100644 index 0000000..a99b2d7 --- /dev/null +++ b/gcc/testsuite/g++.dg/eh/uncaught2.C @@ -0,0 +1,84 @@ +// { dg-do compile } +// { dg-final { scan-assembler-not "__cxa_get_exception" } } +// { dg-options "-fno-use-cxa-get-exception-ptr" } + +#include +#include + + +struct Check { + int obj1, obj2; + bool state; +}; + +static Check const data[] = { + { 0, 0, false }, // construct [0] + { 1, 0, true }, // [1] = [0] + { 0, 0, true }, // destruct [0] + { 2, 1, true }, // [2] = [1] + { 2, 2, true }, // destruct [2] + { 3, 1, true }, // [3] = [1] + { 3, 3, false }, // destruct [3] + { 1, 1, false }, // destruct [1] + { 9, 9, false } // end-of-data +}; + +static int pos = 0; + +static void test(int obj1, int obj2, bool state) +{ + if (obj1 != data[pos].obj1) abort (); + if (obj2 != data[pos].obj2) abort (); + if (state != data[pos].state) abort (); + pos++; +} + + +struct S { + int id; + S (); + S (const S &); + ~S (); +}; + +static int next_id = 0; + +S::S() + : id (next_id++) +{ + test (id, id, std::uncaught_exception ()); +} + +S::S(const S &x) + : id (next_id++) +{ + test (id, x.id, std::uncaught_exception ()); +} + +S::~S() +{ + test (id, id, std::uncaught_exception ()); +} + +extern void foo (S *); + +int main() +{ + try + { + try + { + S s0; + throw s0; // s1 is the exception object + } + catch (S s2) + { + throw; + } + } + catch (S s3) + { + } + + return 0; +} diff --git a/gcc/testsuite/g++.dg/eh/uncaught3.C b/gcc/testsuite/g++.dg/eh/uncaught3.C new file mode 100644 index 0000000..4ce4a53 --- /dev/null +++ b/gcc/testsuite/g++.dg/eh/uncaught3.C @@ -0,0 +1,84 @@ +// { dg-do compile { target powerpc*-*-darwin* } } +// { dg-final { scan-assembler-not "__cxa_get_exception" } } +// { dg-options "-mmacosx-version-min=10.4" } + +#include +#include + + +struct Check { + int obj1, obj2; + bool state; +}; + +static Check const data[] = { + { 0, 0, false }, // construct [0] + { 1, 0, true }, // [1] = [0] + { 0, 0, true }, // destruct [0] + { 2, 1, true }, // [2] = [1] + { 2, 2, true }, // destruct [2] + { 3, 1, true }, // [3] = [1] + { 3, 3, false }, // destruct [3] + { 1, 1, false }, // destruct [1] + { 9, 9, false } // end-of-data +}; + +static int pos = 0; + +static void test(int obj1, int obj2, bool state) +{ + if (obj1 != data[pos].obj1) abort (); + if (obj2 != data[pos].obj2) abort (); + if (state != data[pos].state) abort (); + pos++; +} + + +struct S { + int id; + S (); + S (const S &); + ~S (); +}; + +static int next_id = 0; + +S::S() + : id (next_id++) +{ + test (id, id, std::uncaught_exception ()); +} + +S::S(const S &x) + : id (next_id++) +{ + test (id, x.id, std::uncaught_exception ()); +} + +S::~S() +{ + test (id, id, std::uncaught_exception ()); +} + +extern void foo (S *); + +int main() +{ + try + { + try + { + S s0; + throw s0; // s1 is the exception object + } + catch (S s2) + { + throw; + } + } + catch (S s3) + { + } + + return 0; +} -- 2.7.4