From patchwork Thu Apr 6 23:00:27 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: 9668535 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 5215D602B8 for ; Thu, 6 Apr 2017 23:00:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 569EC26E1A for ; Thu, 6 Apr 2017 23:00:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4B87A285DD; Thu, 6 Apr 2017 23:00:41 +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 EA7D026E1A for ; Thu, 6 Apr 2017 23:00:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753042AbdDFXAj (ORCPT ); Thu, 6 Apr 2017 19:00:39 -0400 Received: from mail-wr0-f193.google.com ([209.85.128.193]:34196 "EHLO mail-wr0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752226AbdDFXAi (ORCPT ); Thu, 6 Apr 2017 19:00:38 -0400 Received: by mail-wr0-f193.google.com with SMTP id u18so7293259wrc.1 for ; Thu, 06 Apr 2017 16:00:38 -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=aAgrXoD7CjBlejhMxvP3JMalz2ccwM6lw3s0YduUvRc=; b=efMtrLTa7h4YlD7Dm/jcVScrUiJINx5b4XHvzr/gUhQnGYD2IUgnP3T3XdC3CoHFhR Etv1bWySKNv9CP9K+3/1HajglIm2HK8WW76zWO/+pwKsZQkyAMciB+VIp2wox6shtHky eYm8vBS538Y3sIUa51WX/sZpUDgUwYiENm30YROTyPY6xRekP36Pes4I1+RV+KHMS4zu KXo8+7WoO20bGfyXW86/UchHhyxyZy8yyERG2XjTRBdMPSU98KAcR1jc8rvTvjZWQpNt 1uvzNfWx7WU7eXGiug4ltaDSIndD72S/ipvlOs/nHxuQ45uzNMwKGiJ04UVMd1nX+gup x3ZA== 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=aAgrXoD7CjBlejhMxvP3JMalz2ccwM6lw3s0YduUvRc=; b=VGovr6t9lldGxVB8w+AE1aV0UTLXZMGxRRi1GHByARQv8Hk5BVu24GK7S/wqIoohmg G6sxaM8IExqQ+XeyCWA6O2BC+egtLqx3KPozQoSSoB6NiLKGGvbX9PZ5tDOdCATgu66l qfmchlH4rGpOQcxzwZj2o/eRDYwmDLinS9YiLq76QZcFRyiGOc+ysQbNsP2fWrflU23M 5jDy3AEaBTz9AFT3aWOhLzCVvaO8WVISFYgI1bRhiEuJPHGXSp8LzIG9WSDOqtkepDhZ qLAjHOfNzwpMu0jx97ovjY+IPl/ef7GBKkZHJkP8fR7tft3syuTxeVDCutaRzIgB+Sc0 y0dQ== X-Gm-Message-State: AFeK/H191DqLti7lufGmgzCFj/lX9uI4ohnXvsCPmDfJoKEJzCLOiA1R9GhOtmAPEVNXeg== X-Received: by 10.28.218.197 with SMTP id r188mr26297597wmg.0.1491519637361; Thu, 06 Apr 2017 16:00:37 -0700 (PDT) Received: from localhost.localdomain ([2a02:a03f:88d:1900:b468:4a21:54b4:3699]) by smtp.gmail.com with ESMTPSA id i7sm4019595wmg.30.2017.04.06.16.00.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 06 Apr 2017 16:00:36 -0700 (PDT) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Linus Torvalds , Christopher Li , Luc Van Oostenryck Subject: [PATCH 2/4] remove bit_size & bit_offset from struct access_data Date: Fri, 7 Apr 2017 01:00:27 +0200 Message-Id: <20170406230029.11384-3-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.12.0 In-Reply-To: <20170406230029.11384-1-luc.vanoostenryck@gmail.com> References: <20170406230029.11384-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' and 'alignment' 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 the 'bit_size' is never set for initializers. The bug could be solved by initializing 'bit_size' & 'bit_offset' but it was much simpler (and feel safer) to simply use the values from 'result_type'. Signed-off-by: Luc Van Oostenryck --- linearize.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/linearize.c b/linearize.c index 61c804333..e9610932b 100644 --- a/linearize.c +++ b/linearize.c @@ -844,8 +844,7 @@ struct access_data { struct symbol *source_type; // source ctype 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 + unsigned int offset; // byte offset struct position pos; }; @@ -898,9 +897,6 @@ 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 +944,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 +995,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; }