From patchwork Sun Aug 19 14:52:16 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?J=2E_Neusch=C3=A4fer?= X-Patchwork-Id: 1344341 Return-Path: X-Original-To: patchwork-linux-sparse@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 391FEDF264 for ; Sun, 19 Aug 2012 14:54:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752776Ab2HSOya (ORCPT ); Sun, 19 Aug 2012 10:54:30 -0400 Received: from mailout-de.gmx.net ([213.165.64.22]:37537 "HELO mailout-de.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1752747Ab2HSOy3 (ORCPT ); Sun, 19 Aug 2012 10:54:29 -0400 Received: (qmail invoked by alias); 19 Aug 2012 14:54:27 -0000 Received: from dslb-084-062-230-154.pools.arcor-ip.net (EHLO debian.debian) [84.62.230.154] by mail.gmx.net (mp040) with SMTP; 19 Aug 2012 16:54:27 +0200 X-Authenticated: #41721828 X-Provags-ID: V01U2FsdGVkX19g79NFnopg69BKyqET5T8CiE0HaL0mukyIe1l8gO xGUiQRlaa72T2T From: =?UTF-8?q?Jonathan=20Neusch=C3=A4fer?= To: linux-sparse@vger.kernel.org Cc: =?UTF-8?q?Jonathan=20Neusch=C3=A4fer?= , Pekka Enberg , Christopher Li , Jeff Garzik , Linus Torvalds Subject: [PATCH] sparse, llvm: convert the condition of branch/select to bool Date: Sun, 19 Aug 2012 16:52:16 +0200 Message-Id: <1345387936-25817-1-git-send-email-j.neuschaefer@gmx.net> X-Mailer: git-send-email 1.7.10.4 MIME-Version: 1.0 X-Y-GMX-Trusted: 0 Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org LLVM expects the first argument of "br" and "select" to be of type i1, so add an "icmp ne %src, 0" for other types. Cc: Pekka Enberg Cc: Christopher Li Cc: Jeff Garzik Cc: Linus Torvalds Signed-off-by: Jonathan Neuschäfer --- sparse-llvm.c | 13 +++++++++++-- validation/backend/int-cond.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 validation/backend/int-cond.c diff --git a/sparse-llvm.c b/sparse-llvm.c index 213d42d..e4929e9 100644 --- a/sparse-llvm.c +++ b/sparse-llvm.c @@ -650,10 +650,19 @@ static void output_op_store(struct function *fn, struct instruction *insn) insn->target->priv = target; } +static LLVMValueRef bool_value(struct function *fn, LLVMValueRef value) +{ + if (LLVMTypeOf(value) != LLVMInt1Type()) + value = LLVMBuildIsNotNull(fn->builder, value, "cond"); + + return value; +} + static void output_op_br(struct function *fn, struct instruction *br) { if (br->cond) { - LLVMValueRef cond = pseudo_to_value(fn, br, br->cond); + LLVMValueRef cond = bool_value(fn, + pseudo_to_value(fn, br, br->cond)); LLVMBuildCondBr(fn->builder, cond, br->bb_true->priv, @@ -668,7 +677,7 @@ static void output_op_sel(struct function *fn, struct instruction *insn) { LLVMValueRef target, src1, src2, src3; - src1 = pseudo_to_value(fn, insn, insn->src1); + src1 = bool_value(fn, pseudo_to_value(fn, insn, insn->src1)); src2 = pseudo_to_value(fn, insn, insn->src2); src3 = pseudo_to_value(fn, insn, insn->src3); diff --git a/validation/backend/int-cond.c b/validation/backend/int-cond.c new file mode 100644 index 0000000..48b25a7 --- /dev/null +++ b/validation/backend/int-cond.c @@ -0,0 +1,30 @@ +static long foo(long a, long b, long c) +{ + return a? b:c; +} + +static long foo_bool(_Bool a, long b, long c) +{ + return a? b:c; +} + +static long bar(long a, long b, long c) +{ + if (a) + return b; + else + return b + c; +} + +static long bar_bool(_Bool a, long b, long c) +{ + if (a) + return b; + else + return b + c; +} + +/* + * check-name: Non-bool condition values in branch/select + * check-command: ./sparsec -c $file -o tmp.o + */