diff options
author | Jason Merrill <jason@redhat.com> | 2021-07-09 05:45:03 -0400 |
---|---|---|
committer | Jason Merrill <jason@redhat.com> | 2021-07-14 14:59:56 -0400 |
commit | b15e301748f0e042379909e32b3ade439dd8f8f9 (patch) | |
tree | 16cda41375af0b9e2b0f01c9c8305ac7d4f28f9d /gcc | |
parent | 4940166a15193d6583b320f2957af8720745b76c (diff) | |
download | gcc-b15e301748f0e042379909e32b3ade439dd8f8f9.zip gcc-b15e301748f0e042379909e32b3ade439dd8f8f9.tar.gz gcc-b15e301748f0e042379909e32b3ade439dd8f8f9.tar.bz2 |
c++: enable -fdelete-dead-exceptions by default
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.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/c-family/c-opts.c | 4 | ||||
-rw-r--r-- | gcc/doc/invoke.texi | 6 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/torture/pr100382.C | 1 |
3 files changed, 9 insertions, 2 deletions
diff --git a/gcc/c-family/c-opts.c b/gcc/c-family/c-opts.c index 60b5802..1c4e832c 100644 --- a/gcc/c-family/c-opts.c +++ b/gcc/c-family/c-opts.c @@ -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 diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index e67d47a..ea88124 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -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 diff --git a/gcc/testsuite/g++.dg/torture/pr100382.C b/gcc/testsuite/g++.dg/torture/pr100382.C index ffc4182..eac5743 100644 --- a/gcc/testsuite/g++.dg/torture/pr100382.C +++ b/gcc/testsuite/g++.dg/torture/pr100382.C @@ -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; } |