From patchwork Mon Nov 13 15:28:20 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christopher Li X-Patchwork-Id: 10056287 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 55D4560586 for ; Mon, 13 Nov 2017 15:28:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 48D2E28DEF for ; Mon, 13 Nov 2017 15:28:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3DF3429046; Mon, 13 Nov 2017 15:28:26 +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_SIGNED, 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 BB9FC28DEF for ; Mon, 13 Nov 2017 15:28:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753121AbdKMP2Y (ORCPT ); Mon, 13 Nov 2017 10:28:24 -0500 Received: from mail-yw0-f196.google.com ([209.85.161.196]:55970 "EHLO mail-yw0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753210AbdKMP2W (ORCPT ); Mon, 13 Nov 2017 10:28:22 -0500 Received: by mail-yw0-f196.google.com with SMTP id t11so13689828ywg.12 for ; Mon, 13 Nov 2017 07:28:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:sender:from:date:message-id:subject:to; bh=ek6e3mwafGLAvhYntLswIQE7Nj1GW5ICkUgVRmuA7Wc=; b=XvWswjlgnyrzYQ4lkLmIrmatlllPiV3/7CnPnjUqkZZJ6q30fV6/QQBJgMzGlRKzCu vs7QZQA0WluP0HGaWi67J9zlgYFb06q5Xo7tGOCtuzGp74x9p4gGfsTNfLs630d1UC30 Fs6txqpfhE5wE3STQdeBuzlorHp9anKNtui/XEgRrtcG/S7ALl8vsPC/ndDhA4wkPMbH 9exDCu6tJT+kP+BVeJSD7P5xu4B+KIF+8z12/IaxIlQfvAKAVuDGhWhmqeq3Zg0OYu4f twiqCadzuElQIDy8OmVqZDE19Im3Mn8WAt70025D1DwWASgqvcUqfmFQMQvap4ml5jmc 2ZXg== 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:from:date:message-id:subject :to; bh=ek6e3mwafGLAvhYntLswIQE7Nj1GW5ICkUgVRmuA7Wc=; b=LppsOqXbP7fh4/l4fp9Tgal4nn0eV4p2lTXahy9nT5MtMWHBP9ABsdcv/X3zaqbHvq XwZVUc6rpKzNr3XJcRrmlqlYX0wQE5Cpbn+PNAQrLOuu1QHLDnZgzKAMhn2DafcFb/w+ zcIvS3Ti3HoLxCOB+iCSjNaMRT3h2Fp2WV687jdoJU/IU9UljfseJx/WeUnCfDyL4wtP baWq9Mg1TO3/SW4li+uOZ2UZ3Cu9Z6w29cxEfGMflWQInyoParbBh1gCmItd12YK4LJD zUBpIyBVPH0XRalruaJWVwXMrQs3iVqWrCQqmS6jaQHa4CbhO4flAypr4VJPucdPz3kb rl2A== X-Gm-Message-State: AJaThX4XR3qDWiWk9JD9e1Ol7OxPIMwrDhwZbUUwSqi03o+q/j+FjT0u avH/an6BZCRfPD0WjyaUdYkWGYJcee0C8RL3og== X-Google-Smtp-Source: AGs4zMav9NyDwS/TlNoVlEGV47kDFiRipIGZ1vKle4o9B4OKZbebOcYtrgYr/8Rwf2ZCHn94XSCShkCys/VF2jKcaT4= X-Received: by 10.37.135.71 with SMTP id e7mr5943733ybn.519.1510586901173; Mon, 13 Nov 2017 07:28:21 -0800 (PST) MIME-Version: 1.0 Received: by 10.129.103.133 with HTTP; Mon, 13 Nov 2017 07:28:20 -0800 (PST) From: Christopher Li Date: Mon, 13 Nov 2017 23:28:20 +0800 X-Google-Sender-Auth: iY5C41R-e9hnPZxUrG3YdxWjqPI Message-ID: Subject: [PATCH 2/2] V2 sparse-llvm: use pseudo->size to select llvm integer type To: Luc Van Oostenryck , Dibyendu Majumdar , Linux-Sparse 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 Now constant pseudo has size saved in pseudo->size. Use that size to select proper integer type for sparse-llvm. Reported-by: Dibyendu Majumdar Signed-off-by: Christopher Li --- sparse-llvm.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) static LLVMLinkage data_linkage(struct symbol *sym) { if (sym->ctype.modifiers & MOD_STATIC) @@ -360,7 +365,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 = LLVMConstInt(int_type_by_size(pseudo->size), pseudo->value, 1); break; case PSEUDO_ARG: { result = LLVMGetParam(fn->fn, pseudo->nr - 1); diff --git a/sparse-llvm.c b/sparse-llvm.c index 29fb65f1..31f87f0b 100644 --- a/sparse-llvm.c +++ b/sparse-llvm.c @@ -242,25 +242,30 @@ static LLVMTypeRef symbol_type(LLVMModuleRef module, struct symbol *sym) return ret; } -static LLVMTypeRef insn_symbol_type(LLVMModuleRef module, struct instruction *insn) +static LLVMTypeRef int_type_by_size(int size) { - if (insn->type) - return symbol_type(module, insn->type); - - switch (insn->size) { + switch (size) { + case 1: return LLVMInt1Type(); case 8: return LLVMInt8Type(); case 16: return LLVMInt16Type(); case 32: return LLVMInt32Type(); case 64: return LLVMInt64Type(); default: - die("invalid bit size %d", insn->size); + die("invalid bit size %d", size); break; } - return NULL; /* not reached */ } +static LLVMTypeRef insn_symbol_type(LLVMModuleRef module, struct instruction *insn) +{ + if (insn->type) + return symbol_type(module, insn->type); + + return int_type_by_size(insn->size); +} +