linux-sparse.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] avoid infinite loop during simplification
@ 2017-08-12 12:55 Luc Van Oostenryck
  2017-08-12 13:55 ` Christopher Li
  2017-08-12 15:26 ` Christopher Li
  0 siblings, 2 replies; 10+ messages in thread
From: Luc Van Oostenryck @ 2017-08-12 12:55 UTC (permalink / raw)
  To: linux-sparse; +Cc: Christopher Li, Luc Van Oostenryck

Currently, sparse can enter in infinite loops.
The effect can be seen is the normal simplification/CSE
loops but the origin of the problem is not there
(it's some interaction between simplify_loads() and
unreachable code, at least for a good part of them).

On the other hand, on normal code, the number of
simplification/CSE cycle is fairly small: even in big,
complex functions, in 80% of cases only 1 or 2 cycles are
needed. The most extreme I found was 12 cycles and that's
an unique case (on a total of 172000+).

So, avoid to let sparse in infinite loop by stopping
the loop if the number of cycles becomes too high: 16.

Note: this solves all the 77 cases of inifinite loop I found.
Note: of course, this patch doesn't change the fact that
      the generated IR is broken and that the root cause(s)
      must be addressed.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---

The patch is also available in the git repository at:
  git://github.com/lucvoo/sparse.git avoid-infinite-loop--max-cse

 cse.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/cse.c b/cse.c
index 17b3da01a..fa136c370 100644
--- a/cse.c
+++ b/cse.c
@@ -356,13 +356,17 @@ static struct instruction * try_to_cse(struct entrypoint *ep, struct instruction
 	return i1;
 }
 
+#define	MAX_CSE_CYCLES	16
 void cleanup_and_cse(struct entrypoint *ep)
 {
+	int max = MAX_CSE_CYCLES;
 	int i;
 
 	simplify_memops(ep);
 repeat:
 	repeat_phase = 0;
+	if (--max == 0)
+		return;
 	clean_up_insns(ep);
 	if (repeat_phase & REPEAT_CFG_CLEANUP)
 		kill_unreachable_bbs(ep);
-- 
2.14.0


^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2017-08-12 15:29 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-08-12 12:55 [PATCH] avoid infinite loop during simplification Luc Van Oostenryck
2017-08-12 13:55 ` Christopher Li
2017-08-12 14:04   ` Christopher Li
2017-08-12 14:22     ` Luc Van Oostenryck
2017-08-12 14:34       ` Christopher Li
2017-08-12 14:17   ` Luc Van Oostenryck
2017-08-12 14:31     ` Christopher Li
2017-08-12 14:50       ` Luc Van Oostenryck
2017-08-12 15:26 ` Christopher Li
2017-08-12 15:29   ` Luc Van Oostenryck

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 NNTP newsgroup(s).