From patchwork Tue Mar 7 15:33:19 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christopher Li X-Patchwork-Id: 9609327 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 4D0D2604DD for ; Tue, 7 Mar 2017 16:03:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 411AA2841A for ; Tue, 7 Mar 2017 16:03:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 35E0628445; Tue, 7 Mar 2017 16:03:36 +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.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RCVD_IN_SORBS_SPAM,T_DKIM_INVALID,T_TVD_MIME_EPI 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 3FFE12846A for ; Tue, 7 Mar 2017 16:03:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932367AbdCGQDd (ORCPT ); Tue, 7 Mar 2017 11:03:33 -0500 Received: from mail-it0-f49.google.com ([209.85.214.49]:37902 "EHLO mail-it0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755572AbdCGQDS (ORCPT ); Tue, 7 Mar 2017 11:03:18 -0500 Received: by mail-it0-f49.google.com with SMTP id m27so7184583iti.1 for ; Tue, 07 Mar 2017 08:03:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=byc9wh8+nfUYhsBsDR24VkU8r/yKu5IsC6oz782mRsY=; b=RXCcjYY8tTfQPtz7mFiwepvdFTQz1OhqB5lsShFFtj+qY4kSaUhDKT1EpJzWgz/9VM r8Acak9JgYQAWH4NTogFHQ0RaizUzo0nb2gyePVRMQpRwE6HhiNU5TkIc5kDNC0aTulg xLH82YXweSe0T6NUIutjhc+iO2hmP1j+/38aedNTLmEe4oMpEfN8z0Q2OTS31lIr/61x VuCFlzG1bIIrJID18odLJi5tlWLViZpXvMAojXLUrw1ViecQFxZdesu+hihiB97LegcK jgW99aPyIRBeFxPxk80fFY9kBEQObyGi7lNTR134kg01GS13XrF8OjQrlOyBmt3P9KHl mXaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc; bh=byc9wh8+nfUYhsBsDR24VkU8r/yKu5IsC6oz782mRsY=; b=B1LKTtzsHFxiDn6XUOB5pkZ54ICyrTlcAV5BfP9v0gVlq4uQAog1NgHIyo3+p8Qv+v PC7wcxRWN38jGs5z3J5Zb9FUAeFsUxuGmxphiqvGiG172Cs/3VkqPMUpOYbK4BtSS7yC vmsSv6UEpKhF7iBesGVRw8Tg6oLDNZky4mgj3HQpb6AFcjwukwz1j0pgGlHVAhsO6x94 5AShIqUS0Mc5RDQczZbVuzc0RFCHvM5Tl4/+xqcUJGGfuBclo6XCWnPK6hHGqwI0aong ICfjZR6OifvN7UnOPi8MX/qvIVi0Y1Rn1aHenuIrP84idjab+Wj4hWqfjE9tWPcTQXAv rbRg== X-Gm-Message-State: AMke39khVG0Q/RrNFz2Kvr+ORkCfflfZN+rAvmOBKagXotWGITxLqzruHDVQEwJgCy5tmPgUODFJZm7VdhPNpQ== X-Received: by 10.36.3.73 with SMTP id e70mr1284975ite.14.1488900799608; Tue, 07 Mar 2017 07:33:19 -0800 (PST) MIME-Version: 1.0 Received: by 10.36.23.135 with HTTP; Tue, 7 Mar 2017 07:33:19 -0800 (PST) In-Reply-To: <20170305112047.3411-7-luc.vanoostenryck@gmail.com> References: <20170305112047.3411-1-luc.vanoostenryck@gmail.com> <20170305112047.3411-7-luc.vanoostenryck@gmail.com> From: Christopher Li Date: Tue, 7 Mar 2017 23:33:19 +0800 X-Google-Sender-Auth: IvQBYx8q7VP1nRtsIJKCAgYFEp0 Message-ID: Subject: Re: [PATCH 06/13] llvm: fix type of literal integer passed as arguments To: Luc Van Oostenryck Cc: Linux-Sparse , Dibyendu Majumdar 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 On Sun, Mar 5, 2017 at 7:20 PM, Luc Van Oostenryck wrote: > Like for all others instructions, LLVM needs the type > of each operands. However this information is not always > available via the pseudo, like here when passing a integer > constant as argument since for sparse constants are typeless. > > Fix this by getting the type via the function prototype. > > + LLVMValueRef value; > + if (arg->type == PSEUDO_VAL) { > + /* Value pseudos do not have type information. */ > + /* Use the function prototype to get the type. */ > + struct symbol *ctype = get_nth1_arg(insn->func->sym, i + 1); I try to come up with an example to use the PREPARE_PTR_LIST() in this patch. I hit a bug "insn->func->sym" assume "insn->func" is a function symbol node. If "insn->func" is a function pointer then access "insn->func->sym" is wrong. Any way, my modify patch attached. It should work similar to this patch without using the nth argument help function. My limited test hit this function pointer bug. Chris From patchwork Sun Mar 5 11:20:40 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [06/13] llvm: fix type of literal integer passed as arguments From: Luc Van Oostenryck X-Patchwork-Id: 9604557 Message-Id: <20170305112047.3411-7-luc.vanoostenryck@gmail.com> To: linux-sparse@vger.kernel.org Cc: Dibyendu Majumdar , Luc Van Oostenryck Date: Sun, 5 Mar 2017 12:20:40 +0100 Like for all others instructions, LLVM needs the type of each operands. However this information is not always available via the pseudo, like here when passing a integer constant as argument since for sparse constants are typeless. Fix this by getting the type via the function prototype. Reported-by: Dibyendu Majumdar Signed-off-by: Luc Van Oostenryck --- sparse-llvm.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) --- sparse.chrisl.orig/sparse-llvm.c +++ sparse.chrisl/sparse-llvm.c @@ -729,6 +729,8 @@ static void output_op_call(struct functi { LLVMValueRef target, func; int n_arg = 0, i; + struct symbol_list *argument_types = insn->func->sym->ctype.base_type->arguments; + struct symbol *argtype; struct pseudo *arg; LLVMValueRef *args; @@ -739,9 +741,20 @@ static void output_op_call(struct functi args = calloc(n_arg, sizeof(LLVMValueRef)); i = 0; + PREPARE_PTR_LIST(argument_types, argtype); FOR_EACH_PTR(insn->arguments, arg) { - args[i++] = pseudo_to_value(fn, insn, arg); + LLVMValueRef value; + if (arg->type == PSEUDO_VAL) { + /* Value pseudos do not have type information. */ + /* Use the function prototype to get the type. */ + value = val_to_value(fn, arg->value, argtype); + } else { + value = pseudo_to_value(fn, insn, arg); + } + args[i++] = value; + NEXT_PTR_LIST(argtype); } END_FOR_EACH_PTR(arg); + FINISH_PTR_LIST(argtype); func = pseudo_to_value(fn, insn, insn->func); target = LLVMBuildCall(fn->builder, func, args, n_arg, "");