From patchwork Tue Aug 8 23:06:30 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: 9889237 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 5308E60363 for ; Tue, 8 Aug 2017 23:07:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3AF332891C for ; Tue, 8 Aug 2017 23:07:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2DE1128A1D; Tue, 8 Aug 2017 23:07:03 +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_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, 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 D593C2891C for ; Tue, 8 Aug 2017 23:07:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752519AbdHHXG7 (ORCPT ); Tue, 8 Aug 2017 19:06:59 -0400 Received: from mail-wm0-f67.google.com ([74.125.82.67]:35563 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752475AbdHHXG5 (ORCPT ); Tue, 8 Aug 2017 19:06:57 -0400 Received: by mail-wm0-f67.google.com with SMTP id r77so4920340wmd.2 for ; Tue, 08 Aug 2017 16:06:57 -0700 (PDT) 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=KeAUxgn8qGHyIf7oy58/I+ufOGqxnOKmo3WNirTwtsk=; b=X5zclmNCbjXm9FjuRr0p9BeS2eaZZBJxNK//sn1JmcRcDWf3BZ3BVGdDZypBQW4E1y TWE/e2bkaOuOS4zcabTkZbUVRF/ka1JkZCpJaKAvuNmj+ulbdknq8cPmvIO07Fgcrf/q xBux0Q1mvMMwO+EqW0mo4vVEXrM/4UHt58nm3H640nDPOVibc3vRn5ryLZZX1L76J9ag Lx7/ZaJuR8Mu6qIh0EA97nBWTMGIjT8gznR3WXHw4sCr+OMJ8lQRCWzAHKtN+kMWj7j+ JwF+Wb2oph+BYpYe9iMQ5oy+oZpZo/zbSQ1Jbk2ZuwCUO6sz6AUdRE87/tT8wriwcY/M 0txA== 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=KeAUxgn8qGHyIf7oy58/I+ufOGqxnOKmo3WNirTwtsk=; b=PIrZ6CryO13HegE74jJpRrvI0NV+bS/CILlkf6ieTXtJG8gCiL9CQacNRbRvUYP7aI F6pMVfgCOQT/HXkyVufn7lUXSwCrjz5lfaVUzOt07r2Oqt22wzJHCPgXXGg+XEk82rUM gbIC+HDmjjF+yFG81kuUlo+r8Ba1jaDIuQsv8AMHlbZOwuq9OB7OnH7hF2vhgFbllYZR GyIOGCCMki8m3DUyVPrv2WC8JQYl+u7T8CLC2FELkpU4lWDfbS/9dMy2zqREgvqrbPX7 eB5dRXqZ+9OU9dt142pi8WdlmLB2QNEGNE+tO9xThoaseOUCOfpdg1DAM83spIx4EzZv J0jA== X-Gm-Message-State: AHYfb5g2LgCn1DlNKaJCYLZAKKnHXAyYZaOQtnQTQwxsFZCS3OkqeBzh JRdkMGaNYmEo1IWbJL4= X-Received: by 10.80.211.22 with SMTP id g22mr5833952edh.167.1502233616241; Tue, 08 Aug 2017 16:06:56 -0700 (PDT) Received: from localhost.localdomain ([2a02:a03f:4076:600:6494:649b:1a34:f1b]) by smtp.gmail.com with ESMTPSA id n15sm1133490edb.87.2017.08.08.16.06.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 08 Aug 2017 16:06:55 -0700 (PDT) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Christopher Li , Linus Torvalds , Dibyendu Majumdar , Luc Van Oostenryck Subject: [PATCH v3 4/8] change the masking when loading bitfields Date: Wed, 9 Aug 2017 01:06:30 +0200 Message-Id: <20170808230634.16227-5-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.13.2 In-Reply-To: <20170808230634.16227-1-luc.vanoostenryck@gmail.com> References: <20170808230634.16227-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 To make some simplification easier, change the way the masking is done when loading bitfields. Signed-off-by: Luc Van Oostenryck --- linearize.c | 15 +++++++++------ validation/bitfield-size.c | 6 ++++-- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/linearize.c b/linearize.c index ba76397ea..f833fd8d9 100644 --- a/linearize.c +++ b/linearize.c @@ -1000,14 +1000,17 @@ static pseudo_t linearize_load_gen(struct entrypoint *ep, struct access_data *ad { struct symbol *ctype = ad->result_type; pseudo_t new = add_load(ep, ad); + unsigned int off = ctype->bit_offset; + unsigned int siz = ctype->bit_size; - if (ctype->bit_offset) { - pseudo_t shift = value_pseudo(ctype->bit_offset); - pseudo_t newval = add_binary_op(ep, ad->source_type, OP_LSR, new, shift); - new = newval; + if (siz != type_size(ad->source_type)) { + pseudo_t mask = value_pseudo(((1ULL << siz) - 1) << off); + new = add_binary_op(ep, ad->source_type, OP_AND, new, mask); + } + if (off) { + pseudo_t shift = value_pseudo(off); + new = add_binary_op(ep, ad->source_type, OP_LSR, new, shift); } - if (ctype->bit_size != type_size(ad->source_type)) - new = cast_pseudo(ep, new, ad->source_type, ad->result_type); return new; } diff --git a/validation/bitfield-size.c b/validation/bitfield-size.c index ce78ecf21..c8c94bb15 100644 --- a/validation/bitfield-size.c +++ b/validation/bitfield-size.c @@ -35,7 +35,9 @@ unsigned int get_pbfi_b(struct bfi *bf) { return bf->b; } * check-command: test-linearize -Wno-decl $file * check-output-ignore * - * check-output-pattern-24-times: cast\\. - * check-output-pattern-12-times: cast\\.4 + * check-output-excludes: cast\\.4 + * check-output-pattern-6-times: cast\\. * check-output-pattern-6-times: lsr\\..*\\$6 + * check-output-pattern-6-times: and\\..*\\$15 + * check-output-pattern-6-times: and\\..*\\$960 */