From patchwork Sat Apr 8 21:18:57 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: 9671319 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 4EAE460365 for ; Sat, 8 Apr 2017 21:19:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 41A7628387 for ; Sat, 8 Apr 2017 21:19:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3544028421; Sat, 8 Apr 2017 21:19:16 +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 D65E228387 for ; Sat, 8 Apr 2017 21:19:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752256AbdDHVTP (ORCPT ); Sat, 8 Apr 2017 17:19:15 -0400 Received: from mail-wm0-f67.google.com ([74.125.82.67]:33550 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751580AbdDHVTO (ORCPT ); Sat, 8 Apr 2017 17:19:14 -0400 Received: by mail-wm0-f67.google.com with SMTP id o81so3595907wmb.0 for ; Sat, 08 Apr 2017 14:19:14 -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=wSkJuabsMU6wG3+2U/Bdc/s/06sEroo3Ij/xDs7ILY0=; b=XkCWfIDf1VR9Ufg827BqkE1BrO2dayRidKeoZJSxxDZ2Iue4E+qbbkf+n1fupOgKtg CAACYrp2lG+T4i70aiLayposWhkuqRO3J05L/TQAui03RyCrOveo+gV8WHrkLV0Lv5hH WEqu8Iy8JuwRyv7+ZlEdarmobICH1t2+qvtFj966Z5b8oqfaXoumy9FcrV/JbJqtYLhL GDm2RfD6VnKizm4jlA7VG5PCgApDxNkwFcSraegOwsX/5icsplSKYmQBBuH+HXyv0L1l tLucDzPwActoSUnA3Q7BU5Yc0FqhIue3eNOZJ3iU2y7xnafIRqXSX1WqAYid9u6at9lY llXQ== 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=wSkJuabsMU6wG3+2U/Bdc/s/06sEroo3Ij/xDs7ILY0=; b=R+li+Srkd+z5HLpMvUlIa4JOkWwKs2/Gy9ikskgNlRediLjdgxIwnYo+e09s6tYJbY z4d1slfRIoN8R2BkzWqvr7B7XxZvP7TVG+4u1+lZamBPmZSG/AgWYzep6Q/UXnwwAvdy m2rz6nDomt4fShXWnIzz0MZQue9cILCHm9lwejAmZvZrVHD92JdKXf/FrZcS98V8V12R etXW6gWHTAoZ+/blbDlo+PiulKL4SaWZ0A9jTl97XH+ZF58kDpeBh1h37Q09ptjqLbkq 6AIadfb5RgKSJHI6hnioX4aaHmKX91NBfOKhBPl5z+5gvWFL/UqucUfShdoU5tdLZoaO mqzQ== X-Gm-Message-State: AN3rC/5p2+Ykv6r8CNfOW7sPqKtN98Cn8nqJNFSqQc2/bqJIbyZ4D5WwjCBhIzHGOE3xzg== X-Received: by 10.28.232.14 with SMTP id f14mr4418017wmh.106.1491686353482; Sat, 08 Apr 2017 14:19:13 -0700 (PDT) Received: from localhost.localdomain ([2a02:a03f:88d:1900:3d63:d6f1:4c06:8f0f]) by smtp.gmail.com with ESMTPSA id n5sm4032362wmf.14.2017.04.08.14.19.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 08 Apr 2017 14:19:13 -0700 (PDT) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Luc Van Oostenryck Subject: [PATCH v2 2/6] remove bit_size & bit_offset from struct access_data Date: Sat, 8 Apr 2017 23:18:57 +0200 Message-Id: <20170408211901.40507-3-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.12.0 In-Reply-To: <20170408211901.40507-1-luc.vanoostenryck@gmail.com> References: <20170408211901.40507-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 struct access_data, the fields: 'bit_offset', 'bit_size' are always the ones corresponding to the 'result_type' and are thus completely redundant. Change this by removing these fields and directly using the info from the 'result_type' field. Note: the motivation for this change is the realization that the initialization of bitfields are buggy because 'bit_size' is never set for initializers. The bug could be solved by initializing 'bit_size' & 'bit_offset' but it is much simpler (and feel safer) to simply use the values from 'result_type'. Signed-off-by: Luc Van Oostenryck --- linearize.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/linearize.c b/linearize.c index 61c804333..5c273a91d 100644 --- a/linearize.c +++ b/linearize.c @@ -845,7 +845,6 @@ struct access_data { pseudo_t address; // pseudo containing address .. pseudo_t origval; // pseudo for original value .. unsigned int offset, alignment; // byte offset - unsigned int bit_size, bit_offset; // which bits struct position pos; }; @@ -898,9 +897,7 @@ static int linearize_address_gen(struct entrypoint *ep, ad->pos = expr->pos; ad->result_type = ctype; ad->source_type = base_type(ctype); - ad->bit_size = ctype->bit_size; ad->alignment = ctype->ctype.alignment; - ad->bit_offset = ctype->bit_offset; if (expr->type == EXPR_PREOP && expr->op == '*') return linearize_simple_address(ep, expr->unop, ad); @@ -948,9 +945,11 @@ static pseudo_t linearize_store_gen(struct entrypoint *ep, pseudo_t store = value; if (type_size(ad->source_type) != type_size(ad->result_type)) { + struct symbol *ctype = ad->result_type; + unsigned int shift = ctype->bit_offset; + unsigned int size = ctype->bit_size; pseudo_t orig = add_load(ep, ad); - int shift = ad->bit_offset; - unsigned long long mask = (1ULL << ad->bit_size)-1; + unsigned long long mask = (1ULL << size) - 1; if (shift) { store = add_binary_op(ep, ad->source_type, OP_SHL, value, value_pseudo(shift)); @@ -997,14 +996,15 @@ static pseudo_t add_symbol_address(struct entrypoint *ep, struct symbol *sym) 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); - if (ad->bit_offset) { - pseudo_t shift = value_pseudo(ad->bit_offset); + 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 (ad->bit_size != type_size(ad->source_type)) + if (ctype->bit_size != type_size(ad->source_type)) new = cast_pseudo(ep, new, ad->source_type, ad->result_type); return new; }