From patchwork Mon Aug 7 01:33:37 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: 9884199 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 60F6460364 for ; Mon, 7 Aug 2017 01:33:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 535C728577 for ; Mon, 7 Aug 2017 01:33:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4822F2857B; Mon, 7 Aug 2017 01:33:51 +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 EA81E28577 for ; Mon, 7 Aug 2017 01:33:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751429AbdHGBdu (ORCPT ); Sun, 6 Aug 2017 21:33:50 -0400 Received: from mail-wm0-f65.google.com ([74.125.82.65]:35361 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751375AbdHGBdu (ORCPT ); Sun, 6 Aug 2017 21:33:50 -0400 Received: by mail-wm0-f65.google.com with SMTP id r77so12119465wmd.2 for ; Sun, 06 Aug 2017 18:33:49 -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=MQRw8+4ht2FJNkPoSR+gVd0X116JTQg9UBNL/5JzNnc=; b=piG82ZZ15JxujOVoPrz1paWlUGujrgHpoKMv+JQwSJ0PS+RuWUfx2dy8RYtpBZjFpd 55q3jQJz0YW/7qboSrziYJc1ZGQr3bE6LFtoouelxdCs4FDdA4LaxUCQ7NooqniujbwI RxLKHXwSbjx0TfLjVG2UY5bcWrT+m8EurLg3wp9Tfgt8gcPGTQXdr0V83H8rbllO2oY8 v9o1UtTyTwPoqRT3lr7Ney8CVTtACcVcURhgZbN3qq7vdo24vlNRC2D0tTWQWdpXYt5E dGkeX8EjauIx4noN1RCeXQB6ZxHyo5qKj8+pFJ+6jWjrTkkQcsNtsR2gjGpQPfbX0Z16 bAyA== 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=MQRw8+4ht2FJNkPoSR+gVd0X116JTQg9UBNL/5JzNnc=; b=LZ8v7wm5bkJe1Cx3kpT5fpmPnOX2onb4Tt/Y+KKpEEiM8oNKi+V8f0lL85CchPPjSg jIjjH6ZCOP6+3sTcYj8Dns6T7KjwytQwpi5xSSHe1t/0robmKEhivBxCJlolsmvXf6WZ 64ecYxxMlr7NkSakYk/V898d7x51XizePP9SKXdtuyAj87udcPCA6/cm+NUYWLmlUSBg tKStK0dL/8bzI5gKDtHIN2m7NThhAziHow3pbh+nBsTczNosblhWgyIhX83g5rYtOHqD ATiCOqBB4bfia9gq8iW0lzPpJWocgvMqC/TjlaUchstSy3oj2fiz6B9GA4eeA9y99vxh UbIA== X-Gm-Message-State: AHYfb5iuZ2Z4nZgIAEjXqsK+trxE06bGFT2dxCieO0WcEqM5lSVbT1Ks /kTlhvz0OOcdWg== X-Received: by 10.80.138.218 with SMTP id k26mr2856628edk.239.1502069629108; Sun, 06 Aug 2017 18:33:49 -0700 (PDT) Received: from localhost.localdomain ([2a02:a03f:4076:600:ac70:e17d:ec67:ee66]) by smtp.gmail.com with ESMTPSA id f29sm5937685edd.23.2017.08.06.18.33.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 06 Aug 2017 18:33:48 -0700 (PDT) From: Luc Van Oostenryck To: Dibyendu Majumdar Cc: linux-sparse@vger.kernel.org, Luc Van Oostenryck Subject: [PATCH 2/3] change loading of bitfields Date: Mon, 7 Aug 2017 03:33:37 +0200 Message-Id: <20170807013338.46211-3-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.13.2 In-Reply-To: <20170807013338.46211-1-luc.vanoostenryck@gmail.com> References: <20170807013338.46211-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 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 af46191f1..b06cf4e19 100644 --- a/linearize.c +++ b/linearize.c @@ -1077,14 +1077,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 */