]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: enable -fdelete-dead-exceptions by default
authorJason Merrill <jason@redhat.com>
Fri, 9 Jul 2021 09:45:03 +0000 (05:45 -0400)
committerJason Merrill <jason@redhat.com>
Wed, 14 Jul 2021 18:59:56 +0000 (14:59 -0400)
As I was discussing with richi, I don't think it makes sense to protect
calls to pure/const functions from DCE just because they aren't explicitly
declared noexcept.  PR100382 indicates that there are different
considerations for Go, which has non-call exceptions.  But still turn the
flag off for that specific testcase.

gcc/c-family/ChangeLog:

* c-opts.c (c_common_post_options): Set -fdelete-dead-exceptions.

gcc/ChangeLog:

* doc/invoke.texi: -fdelete-dead-exceptions is on by default for
C++.

gcc/testsuite/ChangeLog:

* g++.dg/torture/pr100382.C: Pass -fno-delete-dead-exceptions.

gcc/c-family/c-opts.c
gcc/doc/invoke.texi
gcc/testsuite/g++.dg/torture/pr100382.C

index 60b5802722ced2f11f3016050f53102eae7dad22..1c4e832c7ed09c60ba847ad8ef2d7c34bdca83b6 100644 (file)
@@ -1015,6 +1015,10 @@ c_common_post_options (const char **pfilename)
   SET_OPTION_IF_UNSET (&global_options, &global_options_set, flag_finite_loops,
                       optimize >= 2 && cxx_dialect >= cxx11);
 
+  /* It's OK to discard calls to pure/const functions that might throw.  */
+  SET_OPTION_IF_UNSET (&global_options, &global_options_set,
+                      flag_delete_dead_exceptions, true);
+
   if (cxx_dialect >= cxx11)
     {
       /* If we're allowing C++0x constructs, don't warn about C++98
index e67d47af676db9c1c075974138541cdb140df501..ea8812425e95245c4f910b6db0b7d4b00991ee50 100644 (file)
@@ -16335,8 +16335,10 @@ arbitrary signal handlers such as @code{SIGALRM}.
 @opindex fdelete-dead-exceptions
 Consider that instructions that may throw exceptions but don't otherwise
 contribute to the execution of the program can be optimized away.
-This option is enabled by default for the Ada compiler, as permitted by
-the Ada language specification.
+This does not affect calls to functions except those with the
+@code{pure} or @code{const} attributes.
+This option is enabled by default for the Ada and C++ compilers, as permitted by
+the language specifications.
 Optimization passes that cause dead exceptions to be removed are enabled independently at different optimization levels.
 
 @item -funwind-tables
index ffc4182cfceacf137331ae82213685c8db42c266..eac5743b956d59484075cd5014358e5be9758433 100644 (file)
@@ -1,4 +1,5 @@
 // { dg-do run }
+// { dg-additional-options -fno-delete-dead-exceptions }
 
 int x, y;
 int __attribute__((pure,noinline)) foo () { if (x) throw 1; return y; }