Index: gcc/ChangeLog
authorgeoffk <geoffk@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 24 Feb 2006 21:43:01 +0000 (21:43 +0000)
committergeoffk <geoffk@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 24 Feb 2006 21:43:01 +0000 (21:43 +0000)
2006-02-24  Geoffrey Keating  <geoffk@apple.com>

* 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  <geoffk@apple.com>

* 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  <geoffk@apple.com>

* 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

16 files changed:
gcc/ChangeLog
gcc/c-common.c
gcc/c-common.h
gcc/c-opts.c
gcc/c.opt
gcc/config/rs6000/darwin.h
gcc/configure
gcc/configure.ac
gcc/cp/ChangeLog
gcc/cp/except.c
gcc/doc/invoke.texi
gcc/doc/tm.texi
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/eh/uncaught1.C
gcc/testsuite/g++.dg/eh/uncaught2.C [new file with mode: 0644]
gcc/testsuite/g++.dg/eh/uncaught3.C [new file with mode: 0644]

index 0fef1ea..d541925 100644 (file)
@@ -1,3 +1,20 @@
+2006-02-24  Geoffrey Keating  <geoffk@apple.com>
+
+       * 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  <roger@eyesopen.com>
 
        PR middle-end/24952
index 759a68c..4f8ab8e 100644 (file)
@@ -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.  */
 
index 6498255..ed93f97 100644 (file)
@@ -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.  */
 
index 00a8631..c53238b 100644 (file)
@@ -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.  */
index 8f58d3d..1fd12f7 100644 (file)
--- 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
index 46119c8..30a2fff 100644 (file)
   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
index b07c286..fe6f1bd 100755 (executable)
@@ -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
index 1b8feab..447f827 100644 (file)
@@ -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
index c888a09..a1df2bb 100644 (file)
@@ -1,3 +1,8 @@
+2006-02-24  Geoffrey Keating  <geoffk@apple.com>
+
+       * except.c (expand_start_catch_block): Handle
+       flag_use_cxa_get_exception_ptr.
+
 2006-02-22  Volker Reichelt  <reichelt@igpm.rwth-aachen.de>
 
        PR c++/26291
index 8d68486..87e9586 100644 (file)
@@ -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);
index 029b43c..a81ab58 100644 (file)
@@ -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
index dd57867..cebb71c 100644 (file)
@@ -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
index c1d4744..1d4bef3 100644 (file)
@@ -1,3 +1,9 @@
+2006-02-24  Geoffrey Keating  <geoffk@apple.com>
+
+       * 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  <jvdelisle@gcc.gnu.org>
 
        PR libgfortran/26423
index 2aa1068..afbf5af 100644 (file)
@@ -1,5 +1,6 @@
 // PR libstdc++/10606
 // { dg-do run }
+// { dg-options "-fuse-cxa-get-exception-ptr" { target powerpc*-*-darwin* } }
 
 #include <exception>
 #include <cstdlib>
diff --git a/gcc/testsuite/g++.dg/eh/uncaught2.C b/gcc/testsuite/g++.dg/eh/uncaught2.C
new file mode 100644 (file)
index 0000000..a99b2d7
--- /dev/null
@@ -0,0 +1,84 @@
+// { dg-do compile }
+// { dg-final { scan-assembler-not "__cxa_get_exception" } }
+// { dg-options "-fno-use-cxa-get-exception-ptr" }
+
+#include <exception>
+#include <cstdlib>
+
+
+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 (file)
index 0000000..4ce4a53
--- /dev/null
@@ -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 <exception>
+#include <cstdlib>
+
+
+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;
+}