From patchwork Sun Mar 5 11:20:36 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Van Oostenryck X-Patchwork-Id: 9604547 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 317EF60414 for ; Sun, 5 Mar 2017 11:28:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 167172818E for ; Sun, 5 Mar 2017 11:28:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 07CDA283BC; Sun, 5 Mar 2017 11:28:55 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 977392818E for ; Sun, 5 Mar 2017 11:28:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752362AbdCEL2y (ORCPT ); Sun, 5 Mar 2017 06:28:54 -0500 Received: from mail-wm0-f67.google.com ([74.125.82.67]:36308 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751539AbdCEL2y (ORCPT ); Sun, 5 Mar 2017 06:28:54 -0500 Received: by mail-wm0-f67.google.com with SMTP id v190so9488800wme.3 for ; Sun, 05 Mar 2017 03:28:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=aXnXm5FBYKsp4ycQRwgJHu4jcmYF+6TUu+FPLs4YtQs=; b=uLFQphEEvY+PP9J+fR824RcSD/152/b79YSH1GK4AL9LD/4ZDP0c47MBzfwYLNTE0Q UguiYPpRbrVC4Hm9TBBNJPF81oHmRvnWU2bllLf6p99bwre+emo1IU/CcbYUUuTLS1XR kdMcpVZ+2+nX4ltNwzFuBC/BHv5cUl8ibPAvPqJqFu5DeLspjlI9XL4A275ZMLrOoe5A MR7ih2UC0fWOeaXe7A2e8NKpHYOBwWRF3rHOP1U99mdoDtJgBq3m9g/8fiZF/l7JAcaY ps5GJQ9/Xtl6n+TxDHJ85T2EOBvE/aNbVDwdlzyZgPkaKL2SqFJ2dGYMhFVHZC1xxiJJ MHEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=aXnXm5FBYKsp4ycQRwgJHu4jcmYF+6TUu+FPLs4YtQs=; b=YBUCeVasRp44LxSc2MiqwT4dLDXEth5wpTjJGDIJR3cBU8Yosmbk7+w/Az2lEAH1dG GwlhZU7UdHmrkkPRbIHChMv5ELXatvxn4hguxSoviwZrCALMiX91dy4YvU6yOw7ekepR lLC9+wo2k6c7+oJEgglpkCe5fEGKmiWL2LF5tXhUgRt0Yt70OIW08C2gap9CTjH7ESFT Qc6P2pXbFuacB6NTrzoSfmViFqvATYUqIA5H08xp7QDt2c6VOovgekekD/pMoKXcBe14 Jofe3x1rc4aEd5PUbHltz2KNbUUoGo4oURudScpwhMa1HXTFZt4Uk+SSYdRaqykTc3F8 h+9g== X-Gm-Message-State: AMke39lgA2TxiBkXXd2ra2hUjjAdGEApQfmmpyfKSnWLEy2z6Gjroo2EKX9kpW3HlmlKIg== X-Received: by 10.28.165.147 with SMTP id o141mr9296266wme.67.1488712855808; Sun, 05 Mar 2017 03:20:55 -0800 (PST) Received: from localhost.localdomain ([91.178.178.186]) by smtp.gmail.com with ESMTPSA id d1sm22692382wrb.62.2017.03.05.03.20.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 05 Mar 2017 03:20:55 -0800 (PST) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Dibyendu Majumdar , Luc Van Oostenryck Subject: [PATCH 02/13] llvm: fix translation of PSEUDO_VALs into a ValueRefs Date: Sun, 5 Mar 2017 12:20:36 +0100 Message-Id: <20170305112047.3411-3-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.11.1 In-Reply-To: <20170305112047.3411-1-luc.vanoostenryck@gmail.com> References: <20170305112047.3411-1-luc.vanoostenryck@gmail.com> Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP In sparse-llvm there is the assumption that a PSEUDO_VAL is always of integer type. But this is not always the case: constant pointers, like NULL, are also of the PSEUDO_VAL kind. Fix this by using the newly created helper val_to_value() and using the instruction's type where this pseudo is used as the type of the value. Note: while this patch improve the situation, like for example for the test cases added here, it's still not correct because now we're making the assumption that 'insn->type' is the type we need for the pseudo. This is often true, but certainly not always. For example this is not true for: - OP_STORE/OP_LOAD's insn->src - OP_SET{EQ,...}'s insn->src[12] - probably some others ones - in general, obviously, for any instructions where the target has a different type than the operands. Reported-by: Dibyendu Majumdar Signed-off-by: Luc Van Oostenryck --- sparse-llvm.c | 2 +- validation/backend/null.c | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 validation/backend/null.c diff --git a/sparse-llvm.c b/sparse-llvm.c index 41ee1fa1f..d48b3b20a 100644 --- a/sparse-llvm.c +++ b/sparse-llvm.c @@ -384,7 +384,7 @@ static LLVMValueRef pseudo_to_value(struct function *fn, struct instruction *ins break; } case PSEUDO_VAL: - result = LLVMConstInt(insn_symbol_type(fn->module, insn), pseudo->value, 1); + result = val_to_value(fn, pseudo->value, insn->type); break; case PSEUDO_ARG: { result = LLVMGetParam(fn->fn, pseudo->nr - 1); diff --git a/validation/backend/null.c b/validation/backend/null.c new file mode 100644 index 000000000..5c595c70b --- /dev/null +++ b/validation/backend/null.c @@ -0,0 +1,24 @@ +extern int *ip[]; + +void foo(void); +void foo(void) +{ + ip[0] = (void *)0L; + ip[1] = (int *)0L; + ip[2] = (void *)0; + ip[3] = (int *)0; + ip[4] = (void *)(long)0; + ip[5] = (int *)(long)0; + ip[6] = (void *)123; + ip[7] = (int *)123; + ip[8] = (void *)123L; + ip[9] = (int *)123L; + ip[10] = (void *)(long)123; + ip[11] = (int *)(long)123; +} + +/* + * check-name: store constants to pointer + * check-command: sparse-llvm $file + * check-output-ignore + */