From patchwork Sat Aug 27 16:54:40 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kamil Dudka X-Patchwork-Id: 1104652 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter2.kernel.org (8.14.4/8.14.4) with ESMTP id p7RGwISC018405 for ; Sat, 27 Aug 2011 16:58:18 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751360Ab1H0Q6R (ORCPT ); Sat, 27 Aug 2011 12:58:17 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51250 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751161Ab1H0Q6R (ORCPT ); Sat, 27 Aug 2011 12:58:17 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p7RGvsgj026131 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Sat, 27 Aug 2011 12:57:54 -0400 Received: from vpn1-7-242.ams2.redhat.com (vpn1-7-242.ams2.redhat.com [10.36.7.242]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p7RGvrs8006217; Sat, 27 Aug 2011 12:57:53 -0400 From: Kamil Dudka To: Linus Torvalds Subject: Re: linearize bug? Date: Sat, 27 Aug 2011 18:54:40 +0200 User-Agent: KMail/1.9.10 Cc: Jeff Garzik , "Sparse Mailing-list" , Pekka J Enberg References: <4E588EB8.80808@garzik.org> <4E590F22.6030800@garzik.org> In-Reply-To: MIME-Version: 1.0 Message-Id: <201108271854.40694.kdudka@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter2.kernel.org [140.211.167.43]); Sat, 27 Aug 2011 16:58:18 +0000 (UTC) On Saturday 27 August 2011 17:53:23 Linus Torvalds wrote: > The attached patch is ENTIRELY UNTESTED. The only thing I tested it on > is your test-case. Running "make test" requires stuff that I don't > even have installed, and I'm lazy ;^o It seems to break loops with no conditions. The following piece of code: #include int main() { for(;;) printf(""); } ... translates into: main: .L0x7f233ed67010: call.32 %r2 <- printf, "" ret.32 ... which is obviously wrong. I am not sure if handling that special case separately (as done in the attached patch) is a correct way to fix it. Kamil linearize.c | 11 +++++++---- 1 files changed, 7 insertions(+), 4 deletions(-) diff --git a/linearize.c b/linearize.c index 30e0c9d..9e4b6a4 100644 --- a/linearize.c +++ b/linearize.c @@ -2055,7 +2055,7 @@ pseudo_t linearize_statement(struct entrypoint *ep, struct statement *stmt) struct statement *statement = stmt->iterator_statement; struct statement *post_statement = stmt->iterator_post_statement; struct expression *post_condition = stmt->iterator_post_condition; - struct basic_block *loop_top, *loop_body, *loop_continue, *loop_end; + struct basic_block *loop_body, *loop_continue, *loop_end; concat_symbol_list(stmt->iterator_syms, &ep->syms); linearize_statement(ep, pre_statement); @@ -2078,9 +2078,12 @@ pseudo_t linearize_statement(struct entrypoint *ep, struct statement *stmt) linearize_statement(ep, post_statement); /* No post-condition means that it's the same as the pre-condition */ - if (!post_condition) - linearize_cond_branch(ep, pre_condition, loop_body, loop_end); - else + if (!post_condition) { + if (pre_condition) + linearize_cond_branch(ep, pre_condition, loop_body, loop_end); + else + add_goto(ep, loop_body); + } else linearize_cond_branch(ep, post_condition, loop_body, loop_end); set_activeblock(ep, loop_end); break;