public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/users/aoliva/heads/testme)] detect infinite loops earlier in returning_call_p
@ 2023-06-08 10:59 Alexandre Oliva
0 siblings, 0 replies; 5+ messages in thread
From: Alexandre Oliva @ 2023-06-08 10:59 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:4e561e98ef85bf1962a03ddc2dd570ccdeacfd07
commit 4e561e98ef85bf1962a03ddc2dd570ccdeacfd07
Author: Alexandre Oliva <oliva@adacore.com>
Date: Thu Jun 8 05:39:16 2023 -0300
detect infinite loops earlier in returning_call_p
An infinite loop could create a path as long as the block count in
returning_call_p, and then fail the backwards check if a call is found
before emptying the path.
Return as soon as the path exceeds the block count, and search for
duplicate blocks before allocating more memory for the path, so as to
cut the looping short.
for gcc/ChangeLog
* gimple-harden-control-flow.cc (returning_call_p): Detect
infinite loops sooner.
Diff:
---
gcc/gimple-harden-control-flow.cc | 16 +++++++++++-----
1 file changed, 11 insertions(+), 5 deletions(-)
diff --git a/gcc/gimple-harden-control-flow.cc b/gcc/gimple-harden-control-flow.cc
index 3998fd0d293..044671cab79 100644
--- a/gcc/gimple-harden-control-flow.cc
+++ b/gcc/gimple-harden-control-flow.cc
@@ -19,6 +19,7 @@ along with GCC; see the file COPYING3. If not see
<http://www.gnu.org/licenses/>. */
#include "config.h"
+#define INCLUDE_ALGORITHM /* find */
#include "system.h"
#include "coretypes.h"
#include "backend.h"
@@ -211,14 +212,19 @@ returning_call_p (gcall *call)
return false;
/* Quickly check that there's a path to exit compatible with a
- returning call. Detect infinite loops through the counter. */
- basic_block bb = gimple_bb (call);
+ returning call. Detect infinite loops by limiting the path
+ length to the basic block count, and by looking for duplicate
+ blocks before allocating more memory for the path, for amortized
+ O(n). */
auto_vec<basic_block, 10> path;
- for (int i = n_basic_blocks_for_fn (cfun);
- bb != EXIT_BLOCK_PTR_FOR_FN (cfun) && i--;
+ for (basic_block bb = gimple_bb (call);
+ bb != EXIT_BLOCK_PTR_FOR_FN (cfun);
bb = single_succ (bb))
if (!single_succ_p (bb)
- || (single_succ_edge (bb)->flags & EDGE_EH) != 0)
+ || (single_succ_edge (bb)->flags & EDGE_EH) != 0
+ || n_basic_blocks_for_fn (cfun) - path.length () <= NUM_FIXED_BLOCKS
+ || (path.length () == path.allocated ()
+ && std::find (path.begin (), path.end (), bb) != path.end ()))
return false;
else
path.safe_push (bb);
^ permalink raw reply [flat|nested] 5+ messages in thread
* [gcc(refs/users/aoliva/heads/testme)] detect infinite loops earlier in returning_call_p
@ 2023-06-09 8:07 Alexandre Oliva
0 siblings, 0 replies; 5+ messages in thread
From: Alexandre Oliva @ 2023-06-09 8:07 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:4ddfd19c07a6b949b03072d7998833f5d3a4f680
commit 4ddfd19c07a6b949b03072d7998833f5d3a4f680
Author: Alexandre Oliva <oliva@adacore.com>
Date: Thu Jun 8 05:55:04 2023 -0300
detect infinite loops earlier in returning_call_p
An infinite loop could create a path as long as the block count in
returning_call_p, and then fail the backwards check if a call is found
before emptying the path.
Return as soon as the path exceeds the block count, and search for
duplicate blocks before allocating more memory for the path, so as to
cut the looping short.
for gcc/ChangeLog
* gimple-harden-control-flow.cc (returning_call_p): Detect
infinite loops sooner.
Diff:
---
gcc/gimple-harden-control-flow.cc | 16 +++++++++++-----
1 file changed, 11 insertions(+), 5 deletions(-)
diff --git a/gcc/gimple-harden-control-flow.cc b/gcc/gimple-harden-control-flow.cc
index 3998fd0d293..044671cab79 100644
--- a/gcc/gimple-harden-control-flow.cc
+++ b/gcc/gimple-harden-control-flow.cc
@@ -19,6 +19,7 @@ along with GCC; see the file COPYING3. If not see
<http://www.gnu.org/licenses/>. */
#include "config.h"
+#define INCLUDE_ALGORITHM /* find */
#include "system.h"
#include "coretypes.h"
#include "backend.h"
@@ -211,14 +212,19 @@ returning_call_p (gcall *call)
return false;
/* Quickly check that there's a path to exit compatible with a
- returning call. Detect infinite loops through the counter. */
- basic_block bb = gimple_bb (call);
+ returning call. Detect infinite loops by limiting the path
+ length to the basic block count, and by looking for duplicate
+ blocks before allocating more memory for the path, for amortized
+ O(n). */
auto_vec<basic_block, 10> path;
- for (int i = n_basic_blocks_for_fn (cfun);
- bb != EXIT_BLOCK_PTR_FOR_FN (cfun) && i--;
+ for (basic_block bb = gimple_bb (call);
+ bb != EXIT_BLOCK_PTR_FOR_FN (cfun);
bb = single_succ (bb))
if (!single_succ_p (bb)
- || (single_succ_edge (bb)->flags & EDGE_EH) != 0)
+ || (single_succ_edge (bb)->flags & EDGE_EH) != 0
+ || n_basic_blocks_for_fn (cfun) - path.length () <= NUM_FIXED_BLOCKS
+ || (path.length () == path.allocated ()
+ && std::find (path.begin (), path.end (), bb) != path.end ()))
return false;
else
path.safe_push (bb);
^ permalink raw reply [flat|nested] 5+ messages in thread
* [gcc(refs/users/aoliva/heads/testme)] detect infinite loops earlier in returning_call_p
@ 2023-06-09 6:17 Alexandre Oliva
0 siblings, 0 replies; 5+ messages in thread
From: Alexandre Oliva @ 2023-06-09 6:17 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:6269d7a415f9fad7a49f03c8b4a2387d21a9ccc9
commit 6269d7a415f9fad7a49f03c8b4a2387d21a9ccc9
Author: Alexandre Oliva <oliva@adacore.com>
Date: Thu Jun 8 05:55:04 2023 -0300
detect infinite loops earlier in returning_call_p
An infinite loop could create a path as long as the block count in
returning_call_p, and then fail the backwards check if a call is found
before emptying the path.
Return as soon as the path exceeds the block count, and search for
duplicate blocks before allocating more memory for the path, so as to
cut the looping short.
for gcc/ChangeLog
* gimple-harden-control-flow.cc (returning_call_p): Detect
infinite loops sooner.
Diff:
---
gcc/gimple-harden-control-flow.cc | 16 +++++++++++-----
1 file changed, 11 insertions(+), 5 deletions(-)
diff --git a/gcc/gimple-harden-control-flow.cc b/gcc/gimple-harden-control-flow.cc
index 3998fd0d293..044671cab79 100644
--- a/gcc/gimple-harden-control-flow.cc
+++ b/gcc/gimple-harden-control-flow.cc
@@ -19,6 +19,7 @@ along with GCC; see the file COPYING3. If not see
<http://www.gnu.org/licenses/>. */
#include "config.h"
+#define INCLUDE_ALGORITHM /* find */
#include "system.h"
#include "coretypes.h"
#include "backend.h"
@@ -211,14 +212,19 @@ returning_call_p (gcall *call)
return false;
/* Quickly check that there's a path to exit compatible with a
- returning call. Detect infinite loops through the counter. */
- basic_block bb = gimple_bb (call);
+ returning call. Detect infinite loops by limiting the path
+ length to the basic block count, and by looking for duplicate
+ blocks before allocating more memory for the path, for amortized
+ O(n). */
auto_vec<basic_block, 10> path;
- for (int i = n_basic_blocks_for_fn (cfun);
- bb != EXIT_BLOCK_PTR_FOR_FN (cfun) && i--;
+ for (basic_block bb = gimple_bb (call);
+ bb != EXIT_BLOCK_PTR_FOR_FN (cfun);
bb = single_succ (bb))
if (!single_succ_p (bb)
- || (single_succ_edge (bb)->flags & EDGE_EH) != 0)
+ || (single_succ_edge (bb)->flags & EDGE_EH) != 0
+ || n_basic_blocks_for_fn (cfun) - path.length () <= NUM_FIXED_BLOCKS
+ || (path.length () == path.allocated ()
+ && std::find (path.begin (), path.end (), bb) != path.end ()))
return false;
else
path.safe_push (bb);
^ permalink raw reply [flat|nested] 5+ messages in thread
* [gcc(refs/users/aoliva/heads/testme)] detect infinite loops earlier in returning_call_p
@ 2023-06-08 10:43 Alexandre Oliva
0 siblings, 0 replies; 5+ messages in thread
From: Alexandre Oliva @ 2023-06-08 10:43 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:7d38268b50c21a5c393057d7fc7e9bea8b1b8374
commit 7d38268b50c21a5c393057d7fc7e9bea8b1b8374
Author: Alexandre Oliva <oliva@adacore.com>
Date: Thu Jun 8 05:55:04 2023 -0300
detect infinite loops earlier in returning_call_p
An infinite loop could create a path as long as the block count in
returning_call_p, and then fail the backwards check if a call is found
before emptying the path.
Return as soon as the path exceeds the block count, and search for
duplicate blocks before allocating more memory for the path, so as to
cut the looping short.
for gcc/ChangeLog
* gimple-harden-control-flow.cc (returning_call_p): Detect
infinite loops sooner.
Diff:
---
gcc/gimple-harden-control-flow.cc | 16 +++++++++++-----
1 file changed, 11 insertions(+), 5 deletions(-)
diff --git a/gcc/gimple-harden-control-flow.cc b/gcc/gimple-harden-control-flow.cc
index 3998fd0d293..044671cab79 100644
--- a/gcc/gimple-harden-control-flow.cc
+++ b/gcc/gimple-harden-control-flow.cc
@@ -19,6 +19,7 @@ along with GCC; see the file COPYING3. If not see
<http://www.gnu.org/licenses/>. */
#include "config.h"
+#define INCLUDE_ALGORITHM /* find */
#include "system.h"
#include "coretypes.h"
#include "backend.h"
@@ -211,14 +212,19 @@ returning_call_p (gcall *call)
return false;
/* Quickly check that there's a path to exit compatible with a
- returning call. Detect infinite loops through the counter. */
- basic_block bb = gimple_bb (call);
+ returning call. Detect infinite loops by limiting the path
+ length to the basic block count, and by looking for duplicate
+ blocks before allocating more memory for the path, for amortized
+ O(n). */
auto_vec<basic_block, 10> path;
- for (int i = n_basic_blocks_for_fn (cfun);
- bb != EXIT_BLOCK_PTR_FOR_FN (cfun) && i--;
+ for (basic_block bb = gimple_bb (call);
+ bb != EXIT_BLOCK_PTR_FOR_FN (cfun);
bb = single_succ (bb))
if (!single_succ_p (bb)
- || (single_succ_edge (bb)->flags & EDGE_EH) != 0)
+ || (single_succ_edge (bb)->flags & EDGE_EH) != 0
+ || n_basic_blocks_for_fn (cfun) - path.length () <= NUM_FIXED_BLOCKS
+ || (path.length () == path.allocated ()
+ && std::find (path.begin (), path.end (), bb) != path.end ()))
return false;
else
path.safe_push (bb);
^ permalink raw reply [flat|nested] 5+ messages in thread
* [gcc(refs/users/aoliva/heads/testme)] detect infinite loops earlier in returning_call_p
@ 2023-06-08 9:17 Alexandre Oliva
0 siblings, 0 replies; 5+ messages in thread
From: Alexandre Oliva @ 2023-06-08 9:17 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:4e561e98ef85bf1962a03ddc2dd570ccdeacfd07
commit 4e561e98ef85bf1962a03ddc2dd570ccdeacfd07
Author: Alexandre Oliva <oliva@adacore.com>
Date: Thu Jun 8 05:39:16 2023 -0300
detect infinite loops earlier in returning_call_p
An infinite loop could create a path as long as the block count in
returning_call_p, and then fail the backwards check if a call is found
before emptying the path.
Return as soon as the path exceeds the block count, and search for
duplicate blocks before allocating more memory for the path, so as to
cut the looping short.
for gcc/ChangeLog
* gimple-harden-control-flow.cc (returning_call_p): Detect
infinite loops sooner.
Diff:
---
gcc/gimple-harden-control-flow.cc | 16 +++++++++++-----
1 file changed, 11 insertions(+), 5 deletions(-)
diff --git a/gcc/gimple-harden-control-flow.cc b/gcc/gimple-harden-control-flow.cc
index 3998fd0d293..044671cab79 100644
--- a/gcc/gimple-harden-control-flow.cc
+++ b/gcc/gimple-harden-control-flow.cc
@@ -19,6 +19,7 @@ along with GCC; see the file COPYING3. If not see
<http://www.gnu.org/licenses/>. */
#include "config.h"
+#define INCLUDE_ALGORITHM /* find */
#include "system.h"
#include "coretypes.h"
#include "backend.h"
@@ -211,14 +212,19 @@ returning_call_p (gcall *call)
return false;
/* Quickly check that there's a path to exit compatible with a
- returning call. Detect infinite loops through the counter. */
- basic_block bb = gimple_bb (call);
+ returning call. Detect infinite loops by limiting the path
+ length to the basic block count, and by looking for duplicate
+ blocks before allocating more memory for the path, for amortized
+ O(n). */
auto_vec<basic_block, 10> path;
- for (int i = n_basic_blocks_for_fn (cfun);
- bb != EXIT_BLOCK_PTR_FOR_FN (cfun) && i--;
+ for (basic_block bb = gimple_bb (call);
+ bb != EXIT_BLOCK_PTR_FOR_FN (cfun);
bb = single_succ (bb))
if (!single_succ_p (bb)
- || (single_succ_edge (bb)->flags & EDGE_EH) != 0)
+ || (single_succ_edge (bb)->flags & EDGE_EH) != 0
+ || n_basic_blocks_for_fn (cfun) - path.length () <= NUM_FIXED_BLOCKS
+ || (path.length () == path.allocated ()
+ && std::find (path.begin (), path.end (), bb) != path.end ()))
return false;
else
path.safe_push (bb);
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-06-09 8:07 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-08 10:59 [gcc(refs/users/aoliva/heads/testme)] detect infinite loops earlier in returning_call_p Alexandre Oliva
-- strict thread matches above, loose matches on Subject: below --
2023-06-09 8:07 Alexandre Oliva
2023-06-09 6:17 Alexandre Oliva
2023-06-08 10:43 Alexandre Oliva
2023-06-08 9:17 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).