linux-sparse.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] compile-i386: do not generate an infinite loop
@ 2009-07-18 21:34 Kamil Dudka
  2009-07-22  8:38 ` Christopher Li
  2009-07-22 16:39 ` Christopher Li
  0 siblings, 2 replies; 11+ messages in thread
From: Kamil Dudka @ 2009-07-18 21:34 UTC (permalink / raw)
  To: Sparse Mailing-list

[-- Attachment #1: Type: text/plain, Size: 175 bytes --]

Hello,

I've probably encountered a bug within compile-i386.c. It generates
an infinite loop for 'while' statement. My testing example and proposed
patch are enclosed.

Kamil

[-- Attachment #2: list.c --]
[-- Type: text/x-csrc, Size: 183 bytes --]

#include <stdlib.h>

typedef void *TItem;

void dispose_list(TItem *list) {
    while (list) {
        TItem *item = list;
        list = (TItem *) *list;
        free(item);
    }
}

[-- Attachment #3: 0001-compile-i386-do-not-generate-an-infinite-loop.patch --]
[-- Type: text/x-diff, Size: 1251 bytes --]

From 60c47d120b577092f0d8fe9001ca6753706dcdbc Mon Sep 17 00:00:00 2001
From: Kamil Dudka <kdudka@redhat.com>
Date: Sat, 18 Jul 2009 23:24:38 +0200
Subject: [PATCH] compile-i386: do not generate an infinite loop

---
 compile-i386.c |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/compile-i386.c b/compile-i386.c
index 37ea52e..abe9313 100644
--- a/compile-i386.c
+++ b/compile-i386.c
@@ -1913,6 +1913,10 @@ static void emit_loop(struct statement *stmt)
 
 	x86_symbol_decl(stmt->iterator_syms);
 	x86_statement(pre_statement);
+	if (!post_condition || post_condition->type != EXPR_VALUE || post_condition->value) {
+		loop_top = new_label();
+		emit_label(loop_top, "loop top");
+	}
 	if (pre_condition) {
 		if (pre_condition->type == EXPR_VALUE) {
 			if (!pre_condition->value) {
@@ -1936,10 +1940,6 @@ static void emit_loop(struct statement *stmt)
 			insn("jz", lbv, NULL, NULL);
 		}
 	}
-	if (!post_condition || post_condition->type != EXPR_VALUE || post_condition->value) {
-		loop_top = new_label();
-		emit_label(loop_top, "loop top");
-	}
 	x86_statement(statement);
 	if (stmt->iterator_continue->used)
 		emit_label(loop_continue, "'continue' iterator");
-- 
1.6.3.3


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

end of thread, other threads:[~2009-07-22 19:30 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-07-18 21:34 [PATCH] compile-i386: do not generate an infinite loop Kamil Dudka
2009-07-22  8:38 ` Christopher Li
2009-07-22  9:24   ` Kamil Dudka
2009-07-22 16:34     ` Christopher Li
2009-07-22 17:21       ` Kamil Dudka
2009-07-22 19:30         ` Christopher Li
2009-07-22 12:45   ` Jeff Garzik
2009-07-22 16:39 ` Christopher Li
2009-07-22 16:51   ` Jeff Garzik
2009-07-22 17:02     ` Kamil Dudka
2009-07-22 19:18     ` Christopher Li

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).