From patchwork Wed Aug 16 15:34:35 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: 9903977 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 5E3DD60231 for ; Wed, 16 Aug 2017 15:35:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 502E222B27 for ; Wed, 16 Aug 2017 15:35:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 450C6286AC; Wed, 16 Aug 2017 15:35: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.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 E3E9A22B27 for ; Wed, 16 Aug 2017 15:35:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751605AbdHPPfZ (ORCPT ); Wed, 16 Aug 2017 11:35:25 -0400 Received: from mail-wr0-f195.google.com ([209.85.128.195]:33974 "EHLO mail-wr0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751569AbdHPPfZ (ORCPT ); Wed, 16 Aug 2017 11:35:25 -0400 Received: by mail-wr0-f195.google.com with SMTP id x43so3697232wrb.1 for ; Wed, 16 Aug 2017 08:35:24 -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=8cT4/bASzK5DY+jS9Sj/J9IMufNFqmv5x4fn8NV4u6I=; b=tKCgDr+hgy4kvL4ZEnlJbU23aUieLpzGu2CoUVBaH03hEJ51noupQKoUF6t963yXbZ lGVyozMsL/65Zor+covj3iowaZz7gUA5f5fIvp0wBfYaqm6F0ucBgig94OU1mhVE501N fODZ/PgSiAAC0NNZfxi27LuS9qSyTGosUzyOzH+Hz4kPx/Atpc7vfD7LcJsEb0cbx/9X bLRaCtwjDm8NjBJpJkF4moFVw/hKC+Z+EzaH1h1Yl9MAfUnOxshi1q+fjteZ3MMdoo7D 8/GV9qbuxtGjNq0v6JcSuyR9cGg9tnPvXa23yjvLEzo6sXeRn1Bs2ioilh5nqk+wo9YH SYTQ== 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=8cT4/bASzK5DY+jS9Sj/J9IMufNFqmv5x4fn8NV4u6I=; b=JfegJomfst2t8UDTyJOy7pJRy+ItqEkb9Xz92cQWKTQwl3U6GN0cTVkNmqIFkT9RUw agX37DRMOzXpp5H1tGLpuYRUk2DitRo+ge369w/ea1jgWcjENqpr1nouLguYYEAUdu/L lMkHkKmZAEoTMIUwECh42wESRGGlWKXqCAO1TSDVlmushVPz+hojiNGdVKLQs5IxtIjd rmIq56Rar+Ec0AP3LqEFO0Z5SmAua2rEVWOloiubTtcOzlv5FHhA+AkCqlfrcr5Ekf1R n6WOHvfGY4Al2RFWYwbZ6rmZdkej3RK4qspsYJt+ZSv5qseeB7+ONsH8qkigjzfLw20h LLwg== X-Gm-Message-State: AHYfb5htA6lSi7k+9vt/fS2NsS0NOmjowVWPNbH4Re61+kdsT0NjbPPw c/icATC2O89GJGkmBJk= X-Received: by 10.80.179.10 with SMTP id q10mr780065edd.298.1502897723671; Wed, 16 Aug 2017 08:35:23 -0700 (PDT) Received: from localhost.localdomain ([2a02:a03f:4076:600:895a:bb88:13f:9772]) by smtp.gmail.com with ESMTPSA id y19sm690635edi.6.2017.08.16.08.35.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 16 Aug 2017 08:35:23 -0700 (PDT) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Linus Torvalds , Christopher Li , Luc Van Oostenryck Subject: [PATCH 09/29] add helper to test if a variable is "simple" Date: Wed, 16 Aug 2017 17:34:35 +0200 Message-Id: <20170816153455.97693-10-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.14.0 In-Reply-To: <20170816153455.97693-1-luc.vanoostenryck@gmail.com> References: <20170816153455.97693-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 Here by 'simple' we really mean 'worth of putting in a register'. We select all scalar types as well as struct and unions with a size not bigger than a long (register). Global and static variables, variables which address have been taken and volatiles variables are never selected. Signed-off-by: Luc Van Oostenryck --- symbol.h | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/symbol.h b/symbol.h index 327449611..3f075c5bc 100644 --- a/symbol.h +++ b/symbol.h @@ -407,6 +407,39 @@ static inline int is_scalar_type(struct symbol *type) return 0; } +static inline int is_simple_type(struct symbol *type) +{ + if (type->type == SYM_NODE) + type = type->ctype.base_type; + switch (type->type) { + case SYM_ENUM: + case SYM_BITFIELD: + case SYM_PTR: + case SYM_RESTRICT: // OK, always integer types + return 1; + case SYM_STRUCT: + case SYM_UNION: + return type->bit_size <= long_ctype.bit_size; + default: + break; + } + if (type->ctype.base_type == &int_type) + return 1; + if (type->ctype.base_type == &fp_type) + return 1; + return 0; +} + +static inline int is_simple_var(struct symbol *var) +{ + if (!is_simple_type(var)) + return 0; +#define MOD_NONREG (MOD_STATIC|MOD_NONLOCAL|MOD_ADDRESSABLE|MOD_VOLATILE) + if (var->ctype.modifiers & MOD_NONREG) + return 0; + return 1; +} + static inline int is_function(struct symbol *type) { return type && type->type == SYM_FN;