public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/users/aoliva/heads/testme)] hardcfr: fix builtin_return noreturn mishandling
@ 2022-10-01 4:50 Alexandre Oliva
0 siblings, 0 replies; 2+ messages in thread
From: Alexandre Oliva @ 2022-10-01 4:50 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:a162f8e5378c2dfeada2c38b5847c953e978c48e
commit a162f8e5378c2dfeada2c38b5847c953e978c48e
Author: Alexandre Oliva <oliva@adacore.com>
Date: Fri Sep 30 23:20:33 2022 -0300
hardcfr: fix builtin_return noreturn mishandling
Diff:
---
gcc/gimple-harden-control-flow.cc | 18 ++++++++++--------
.../c-c++-common/torture/harden-cfr-bret-always.c | 13 +++++++++++++
.../c-c++-common/torture/harden-cfr-bret-never.c | 13 +++++++++++++
.../c-c++-common/torture/harden-cfr-bret-noopt.c | 12 ++++++++++++
.../c-c++-common/torture/harden-cfr-bret-noret.c | 12 ++++++++++++
.../c-c++-common/torture/harden-cfr-bret-nothrow.c | 13 +++++++++++++
.../c-c++-common/torture/harden-cfr-bret-retcl.c | 12 ++++++++++++
gcc/testsuite/c-c++-common/torture/harden-cfr-bret.c | 8 +++++++-
8 files changed, 92 insertions(+), 9 deletions(-)
diff --git a/gcc/gimple-harden-control-flow.cc b/gcc/gimple-harden-control-flow.cc
index 1c93bf622e8..cd5b3cf69b2 100644
--- a/gcc/gimple-harden-control-flow.cc
+++ b/gcc/gimple-harden-control-flow.cc
@@ -1294,12 +1294,15 @@ pass_harden_control_flow_redundancy::execute (function *fun)
continue;
}
- /* If there are no exceptions, then any noreturn call must have
- zero successor edges. Otherwise, check for blocks without
- non-EH successors, but skip those with resx stmts and edges
- (i.e., those other than that in bb_eh_cleanup), since those
- will go through bb_eh_cleanup, that will have been counted as
- noreturn above because it has no successors. */
+ /* If there are no exceptions, it would seem like any noreturn
+ call must have zero successor edges, but __builtin_return
+ gets successor edges. We don't want to handle it here, it
+ will be dealt with in sibcall_search_preds. Otherwise,
+ check for blocks without non-EH successors, but skip those
+ with resx stmts and edges (i.e., those other than that in
+ bb_eh_cleanup), since those will go through bb_eh_cleanup,
+ that will have been counted as noreturn above because it
+ has no successors. */
gcc_checking_assert (bb != bb_eh_cleanup
|| !check_at_escaping_exceptions);
if (flag_exceptions && is_a <gresx *> (stmt)
@@ -1309,8 +1312,7 @@ pass_harden_control_flow_redundancy::execute (function *fun)
? false
: (!flag_exceptions
|| gimple_call_nothrow_p (as_a <gcall *> (stmt)))
- ? (/* Catch cases that should not have successors. */
- gcc_unreachable (), check_before_nothrow_noreturn_calls)
+ ? false /* rather than check_before_nothrow_noreturn_calls */
: always_throwing_noreturn_call_p (stmt)
? check_before_always_throwing_noreturn_calls
: check_before_throwing_noreturn_calls)
diff --git a/gcc/testsuite/c-c++-common/torture/harden-cfr-bret-always.c b/gcc/testsuite/c-c++-common/torture/harden-cfr-bret-always.c
new file mode 100644
index 00000000000..779896c60e8
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/torture/harden-cfr-bret-always.c
@@ -0,0 +1,13 @@
+/* { dg-do compile } */
+/* { dg-options "-fharden-control-flow-redundancy -fhardcfr-check-noreturn-calls=always -fdump-tree-hardcfr -ffat-lto-objects" } */
+
+/* Check that, even enabling all checks before noreturn calls (leaving
+ returning calls enabled), we get checks before __builtin_return without
+ duplication (__builtin_return is both noreturn and a returning call). */
+
+#include "harden-cfr-bret.c"
+
+/* Out-of-line checking, before both builtin_return and return in f. */
+/* { dg-final { scan-tree-dump-times "__hardcfr_check" 2 "hardcfr" } } */
+/* Inline checking before builtin_return in g. */
+/* { dg-final { scan-tree-dump-times "__builtin_trap" 1 "hardcfr" } } */
diff --git a/gcc/testsuite/c-c++-common/torture/harden-cfr-bret-never.c b/gcc/testsuite/c-c++-common/torture/harden-cfr-bret-never.c
new file mode 100644
index 00000000000..49ce17f5b93
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/torture/harden-cfr-bret-never.c
@@ -0,0 +1,13 @@
+/* { dg-do compile } */
+/* { dg-options "-fharden-control-flow-redundancy -fhardcfr-check-noreturn-calls=never -fdump-tree-hardcfr -ffat-lto-objects" } */
+
+/* Check that, even enabling checks before never noreturn calls (leaving
+ returning calls enabled), we get checks before __builtin_return without
+ duplication (__builtin_return is both noreturn and a returning call). */
+
+#include "harden-cfr-bret.c"
+
+/* Out-of-line checking, before both builtin_return and return in f. */
+/* { dg-final { scan-tree-dump-times "__hardcfr_check" 2 "hardcfr" } } */
+/* Inline checking before builtin_return in g. */
+/* { dg-final { scan-tree-dump-times "__builtin_trap" 1 "hardcfr" } } */
diff --git a/gcc/testsuite/c-c++-common/torture/harden-cfr-bret-noopt.c b/gcc/testsuite/c-c++-common/torture/harden-cfr-bret-noopt.c
new file mode 100644
index 00000000000..1512614791f
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/torture/harden-cfr-bret-noopt.c
@@ -0,0 +1,12 @@
+/* { dg-do compile } */
+/* { dg-options "-fharden-control-flow-redundancy -fhardcfr-check-noreturn-calls=never -fno-hardcfr-check-returning-calls -fdump-tree-hardcfr -ffat-lto-objects" } */
+
+/* Check that, even disabling checks before both noreturn and returning
+ calls, we still get checks before __builtin_return. */
+
+#include "harden-cfr-bret.c"
+
+/* Out-of-line checking, before both builtin_return and return in f. */
+/* { dg-final { scan-tree-dump-times "__hardcfr_check" 2 "hardcfr" } } */
+/* Inline checking before builtin_return in g. */
+/* { dg-final { scan-tree-dump-times "__builtin_trap" 1 "hardcfr" } } */
diff --git a/gcc/testsuite/c-c++-common/torture/harden-cfr-bret-noret.c b/gcc/testsuite/c-c++-common/torture/harden-cfr-bret-noret.c
new file mode 100644
index 00000000000..fd95bb7e3e3
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/torture/harden-cfr-bret-noret.c
@@ -0,0 +1,12 @@
+/* { dg-do compile } */
+/* { dg-options "-fharden-control-flow-redundancy -fno-hardcfr-check-returning-calls -fdump-tree-hardcfr -ffat-lto-objects" } */
+
+/* Check that, even disabling checks before returning calls (leaving noreturn
+ calls enabled), we still get checks before __builtin_return. */
+
+#include "harden-cfr-bret.c"
+
+/* Out-of-line checking, before both builtin_return and return in f. */
+/* { dg-final { scan-tree-dump-times "__hardcfr_check" 2 "hardcfr" } } */
+/* Inline checking before builtin_return in g. */
+/* { dg-final { scan-tree-dump-times "__builtin_trap" 1 "hardcfr" } } */
diff --git a/gcc/testsuite/c-c++-common/torture/harden-cfr-bret-nothrow.c b/gcc/testsuite/c-c++-common/torture/harden-cfr-bret-nothrow.c
new file mode 100644
index 00000000000..c5c361234c4
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/torture/harden-cfr-bret-nothrow.c
@@ -0,0 +1,13 @@
+/* { dg-do compile } */
+/* { dg-options "-fharden-control-flow-redundancy -fhardcfr-check-noreturn-calls=nothrow -fdump-tree-hardcfr -ffat-lto-objects" } */
+
+/* Check that, even enabling checks before nothrow noreturn calls (leaving
+ returning calls enabled), we get checks before __builtin_return without
+ duplication (__builtin_return is both noreturn and a returning call). */
+
+#include "harden-cfr-bret.c"
+
+/* Out-of-line checking, before both builtin_return and return in f. */
+/* { dg-final { scan-tree-dump-times "__hardcfr_check" 2 "hardcfr" } } */
+/* Inline checking before builtin_return in g. */
+/* { dg-final { scan-tree-dump-times "__builtin_trap" 1 "hardcfr" } } */
diff --git a/gcc/testsuite/c-c++-common/torture/harden-cfr-bret-retcl.c b/gcc/testsuite/c-c++-common/torture/harden-cfr-bret-retcl.c
new file mode 100644
index 00000000000..137dfbb95d6
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/torture/harden-cfr-bret-retcl.c
@@ -0,0 +1,12 @@
+/* { dg-do compile } */
+/* { dg-options "-fharden-control-flow-redundancy -fhardcfr-check-noreturn-calls=never -fdump-tree-hardcfr -ffat-lto-objects" } */
+
+/* Check that, even disabling checks before noreturn calls (leaving returning
+ calls enabled), we still get checks before __builtin_return. */
+
+#include "harden-cfr-bret.c"
+
+/* Out-of-line checking, before both builtin_return and return in f. */
+/* { dg-final { scan-tree-dump-times "__hardcfr_check" 2 "hardcfr" } } */
+/* Inline checking before builtin_return in g. */
+/* { dg-final { scan-tree-dump-times "__builtin_trap" 1 "hardcfr" } } */
diff --git a/gcc/testsuite/c-c++-common/torture/harden-cfr-bret.c b/gcc/testsuite/c-c++-common/torture/harden-cfr-bret.c
index 70acdc95f25..b459ff6b864 100644
--- a/gcc/testsuite/c-c++-common/torture/harden-cfr-bret.c
+++ b/gcc/testsuite/c-c++-common/torture/harden-cfr-bret.c
@@ -7,5 +7,11 @@ int f(int i) {
return i;
}
-/* Out-of-line checking, before both builtin_return and return. */
+int g(int i) {
+ __builtin_return (&i);
+}
+
+/* Out-of-line checking, before both builtin_return and return in f. */
/* { dg-final { scan-tree-dump-times "__hardcfr_check" 2 "hardcfr" } } */
+/* Inline checking before builtin_return in g. */
+/* { dg-final { scan-tree-dump-times "__builtin_trap" 1 "hardcfr" } } */
^ permalink raw reply [flat|nested] 2+ messages in thread
* [gcc(refs/users/aoliva/heads/testme)] hardcfr: fix builtin_return noreturn mishandling
@ 2022-09-10 3:03 Alexandre Oliva
0 siblings, 0 replies; 2+ messages in thread
From: Alexandre Oliva @ 2022-09-10 3:03 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:3e6d179fa4f5c5ae74a191be7eadb0eb3425cb3a
commit 3e6d179fa4f5c5ae74a191be7eadb0eb3425cb3a
Author: Alexandre Oliva <oliva@gnu.org>
Date: Fri Sep 9 21:18:59 2022 -0300
hardcfr: fix builtin_return noreturn mishandling
Diff:
---
gcc/gimple-harden-control-flow.cc | 18 ++++++++++--------
.../c-c++-common/torture/harden-cfr-bret-always.c | 13 +++++++++++++
.../c-c++-common/torture/harden-cfr-bret-never.c | 13 +++++++++++++
.../c-c++-common/torture/harden-cfr-bret-noopt.c | 12 ++++++++++++
.../c-c++-common/torture/harden-cfr-bret-noret.c | 12 ++++++++++++
.../c-c++-common/torture/harden-cfr-bret-nothrow.c | 13 +++++++++++++
.../c-c++-common/torture/harden-cfr-bret-retcl.c | 12 ++++++++++++
gcc/testsuite/c-c++-common/torture/harden-cfr-bret.c | 8 +++++++-
8 files changed, 92 insertions(+), 9 deletions(-)
diff --git a/gcc/gimple-harden-control-flow.cc b/gcc/gimple-harden-control-flow.cc
index 1c93bf622e8..cd5b3cf69b2 100644
--- a/gcc/gimple-harden-control-flow.cc
+++ b/gcc/gimple-harden-control-flow.cc
@@ -1294,12 +1294,15 @@ pass_harden_control_flow_redundancy::execute (function *fun)
continue;
}
- /* If there are no exceptions, then any noreturn call must have
- zero successor edges. Otherwise, check for blocks without
- non-EH successors, but skip those with resx stmts and edges
- (i.e., those other than that in bb_eh_cleanup), since those
- will go through bb_eh_cleanup, that will have been counted as
- noreturn above because it has no successors. */
+ /* If there are no exceptions, it would seem like any noreturn
+ call must have zero successor edges, but __builtin_return
+ gets successor edges. We don't want to handle it here, it
+ will be dealt with in sibcall_search_preds. Otherwise,
+ check for blocks without non-EH successors, but skip those
+ with resx stmts and edges (i.e., those other than that in
+ bb_eh_cleanup), since those will go through bb_eh_cleanup,
+ that will have been counted as noreturn above because it
+ has no successors. */
gcc_checking_assert (bb != bb_eh_cleanup
|| !check_at_escaping_exceptions);
if (flag_exceptions && is_a <gresx *> (stmt)
@@ -1309,8 +1312,7 @@ pass_harden_control_flow_redundancy::execute (function *fun)
? false
: (!flag_exceptions
|| gimple_call_nothrow_p (as_a <gcall *> (stmt)))
- ? (/* Catch cases that should not have successors. */
- gcc_unreachable (), check_before_nothrow_noreturn_calls)
+ ? false /* rather than check_before_nothrow_noreturn_calls */
: always_throwing_noreturn_call_p (stmt)
? check_before_always_throwing_noreturn_calls
: check_before_throwing_noreturn_calls)
diff --git a/gcc/testsuite/c-c++-common/torture/harden-cfr-bret-always.c b/gcc/testsuite/c-c++-common/torture/harden-cfr-bret-always.c
new file mode 100644
index 00000000000..779896c60e8
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/torture/harden-cfr-bret-always.c
@@ -0,0 +1,13 @@
+/* { dg-do compile } */
+/* { dg-options "-fharden-control-flow-redundancy -fhardcfr-check-noreturn-calls=always -fdump-tree-hardcfr -ffat-lto-objects" } */
+
+/* Check that, even enabling all checks before noreturn calls (leaving
+ returning calls enabled), we get checks before __builtin_return without
+ duplication (__builtin_return is both noreturn and a returning call). */
+
+#include "harden-cfr-bret.c"
+
+/* Out-of-line checking, before both builtin_return and return in f. */
+/* { dg-final { scan-tree-dump-times "__hardcfr_check" 2 "hardcfr" } } */
+/* Inline checking before builtin_return in g. */
+/* { dg-final { scan-tree-dump-times "__builtin_trap" 1 "hardcfr" } } */
diff --git a/gcc/testsuite/c-c++-common/torture/harden-cfr-bret-never.c b/gcc/testsuite/c-c++-common/torture/harden-cfr-bret-never.c
new file mode 100644
index 00000000000..49ce17f5b93
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/torture/harden-cfr-bret-never.c
@@ -0,0 +1,13 @@
+/* { dg-do compile } */
+/* { dg-options "-fharden-control-flow-redundancy -fhardcfr-check-noreturn-calls=never -fdump-tree-hardcfr -ffat-lto-objects" } */
+
+/* Check that, even enabling checks before never noreturn calls (leaving
+ returning calls enabled), we get checks before __builtin_return without
+ duplication (__builtin_return is both noreturn and a returning call). */
+
+#include "harden-cfr-bret.c"
+
+/* Out-of-line checking, before both builtin_return and return in f. */
+/* { dg-final { scan-tree-dump-times "__hardcfr_check" 2 "hardcfr" } } */
+/* Inline checking before builtin_return in g. */
+/* { dg-final { scan-tree-dump-times "__builtin_trap" 1 "hardcfr" } } */
diff --git a/gcc/testsuite/c-c++-common/torture/harden-cfr-bret-noopt.c b/gcc/testsuite/c-c++-common/torture/harden-cfr-bret-noopt.c
new file mode 100644
index 00000000000..1512614791f
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/torture/harden-cfr-bret-noopt.c
@@ -0,0 +1,12 @@
+/* { dg-do compile } */
+/* { dg-options "-fharden-control-flow-redundancy -fhardcfr-check-noreturn-calls=never -fno-hardcfr-check-returning-calls -fdump-tree-hardcfr -ffat-lto-objects" } */
+
+/* Check that, even disabling checks before both noreturn and returning
+ calls, we still get checks before __builtin_return. */
+
+#include "harden-cfr-bret.c"
+
+/* Out-of-line checking, before both builtin_return and return in f. */
+/* { dg-final { scan-tree-dump-times "__hardcfr_check" 2 "hardcfr" } } */
+/* Inline checking before builtin_return in g. */
+/* { dg-final { scan-tree-dump-times "__builtin_trap" 1 "hardcfr" } } */
diff --git a/gcc/testsuite/c-c++-common/torture/harden-cfr-bret-noret.c b/gcc/testsuite/c-c++-common/torture/harden-cfr-bret-noret.c
new file mode 100644
index 00000000000..fd95bb7e3e3
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/torture/harden-cfr-bret-noret.c
@@ -0,0 +1,12 @@
+/* { dg-do compile } */
+/* { dg-options "-fharden-control-flow-redundancy -fno-hardcfr-check-returning-calls -fdump-tree-hardcfr -ffat-lto-objects" } */
+
+/* Check that, even disabling checks before returning calls (leaving noreturn
+ calls enabled), we still get checks before __builtin_return. */
+
+#include "harden-cfr-bret.c"
+
+/* Out-of-line checking, before both builtin_return and return in f. */
+/* { dg-final { scan-tree-dump-times "__hardcfr_check" 2 "hardcfr" } } */
+/* Inline checking before builtin_return in g. */
+/* { dg-final { scan-tree-dump-times "__builtin_trap" 1 "hardcfr" } } */
diff --git a/gcc/testsuite/c-c++-common/torture/harden-cfr-bret-nothrow.c b/gcc/testsuite/c-c++-common/torture/harden-cfr-bret-nothrow.c
new file mode 100644
index 00000000000..c5c361234c4
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/torture/harden-cfr-bret-nothrow.c
@@ -0,0 +1,13 @@
+/* { dg-do compile } */
+/* { dg-options "-fharden-control-flow-redundancy -fhardcfr-check-noreturn-calls=nothrow -fdump-tree-hardcfr -ffat-lto-objects" } */
+
+/* Check that, even enabling checks before nothrow noreturn calls (leaving
+ returning calls enabled), we get checks before __builtin_return without
+ duplication (__builtin_return is both noreturn and a returning call). */
+
+#include "harden-cfr-bret.c"
+
+/* Out-of-line checking, before both builtin_return and return in f. */
+/* { dg-final { scan-tree-dump-times "__hardcfr_check" 2 "hardcfr" } } */
+/* Inline checking before builtin_return in g. */
+/* { dg-final { scan-tree-dump-times "__builtin_trap" 1 "hardcfr" } } */
diff --git a/gcc/testsuite/c-c++-common/torture/harden-cfr-bret-retcl.c b/gcc/testsuite/c-c++-common/torture/harden-cfr-bret-retcl.c
new file mode 100644
index 00000000000..137dfbb95d6
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/torture/harden-cfr-bret-retcl.c
@@ -0,0 +1,12 @@
+/* { dg-do compile } */
+/* { dg-options "-fharden-control-flow-redundancy -fhardcfr-check-noreturn-calls=never -fdump-tree-hardcfr -ffat-lto-objects" } */
+
+/* Check that, even disabling checks before noreturn calls (leaving returning
+ calls enabled), we still get checks before __builtin_return. */
+
+#include "harden-cfr-bret.c"
+
+/* Out-of-line checking, before both builtin_return and return in f. */
+/* { dg-final { scan-tree-dump-times "__hardcfr_check" 2 "hardcfr" } } */
+/* Inline checking before builtin_return in g. */
+/* { dg-final { scan-tree-dump-times "__builtin_trap" 1 "hardcfr" } } */
diff --git a/gcc/testsuite/c-c++-common/torture/harden-cfr-bret.c b/gcc/testsuite/c-c++-common/torture/harden-cfr-bret.c
index 70acdc95f25..b459ff6b864 100644
--- a/gcc/testsuite/c-c++-common/torture/harden-cfr-bret.c
+++ b/gcc/testsuite/c-c++-common/torture/harden-cfr-bret.c
@@ -7,5 +7,11 @@ int f(int i) {
return i;
}
-/* Out-of-line checking, before both builtin_return and return. */
+int g(int i) {
+ __builtin_return (&i);
+}
+
+/* Out-of-line checking, before both builtin_return and return in f. */
/* { dg-final { scan-tree-dump-times "__hardcfr_check" 2 "hardcfr" } } */
+/* Inline checking before builtin_return in g. */
+/* { dg-final { scan-tree-dump-times "__builtin_trap" 1 "hardcfr" } } */
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-10-01 4:50 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-01 4:50 [gcc(refs/users/aoliva/heads/testme)] hardcfr: fix builtin_return noreturn mishandling Alexandre Oliva
-- strict thread matches above, loose matches on Subject: below --
2022-09-10 3:03 Alexandre Oliva
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).