From patchwork Sat Apr 7 09:50:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joey Pabalinas X-Patchwork-Id: 10327779 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 356586053F for ; Sat, 7 Apr 2018 09:50:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 22B9F28C30 for ; Sat, 7 Apr 2018 09:50:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 14A1F29622; Sat, 7 Apr 2018 09:50:54 +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=-5.0 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, FSL_HELO_FAKE, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID,T_TVD_MIME_EPI 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 3542128C30 for ; Sat, 7 Apr 2018 09:50:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751186AbeDGJuw (ORCPT ); Sat, 7 Apr 2018 05:50:52 -0400 Received: from mail-pl0-f67.google.com ([209.85.160.67]:33951 "EHLO mail-pl0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751093AbeDGJuw (ORCPT ); Sat, 7 Apr 2018 05:50:52 -0400 Received: by mail-pl0-f67.google.com with SMTP id y12-v6so2021300plt.1 for ; Sat, 07 Apr 2018 02:50:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :user-agent; bh=aqQB5NyJDCkXM41Sq4yUcC5Uwmq/d40MQYobZS4aKbo=; b=j+0aG+wZRiADjwYfBrWT2ENZz6IuaLf5z1ypXOisN6Ko/dITWjhczcmUteYWcH2ClD fCQkQswtv7N3/ajzsSgNbz/a7pvXvzD6vykg5gRUJ4ZyLnMCHFQrmmWmF1RM/mdtMMHM wkkxd2CtVr41l+CxgdqtIli35rGPteBtY9+wv7qT6/3cO9GH689QB2cUilstQnRgdJMn KrRoFNSHQKmzl4D1wZTeVfBdxRwWLdPBa2AkJ9aiyC4Zl8yxO8M8jnkM9iuSTdti9yQ6 Imo1F13NH3g1X+2tcGQdaRzMns3KzqvKM2k6IeFzH+tNVIy8hCu7AqCmG64Fci9IHS9g VoZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=aqQB5NyJDCkXM41Sq4yUcC5Uwmq/d40MQYobZS4aKbo=; b=QeczvKhUwMVjBUCdGm2bROBR2JiTs8r1BLk6m4/KEWN+3bOYKaOQ5TKUvhFAN5Wvkw vQRlHSkHhpwIo/w2mxsZKuuR7eo7WjitVHTLEl6473wKdrZv3MP5c/1cbAxNRrz+1lzy HeTtPKgNS9AUBfaMLDBC2bhS4Ktu17KoOg5U/JJNEAhRZMiO+gmmCaKjcnuhjerKyvsF kgiMPvFGqgtlT3NNf1hwJcVtwwOGblfIxKQeeu/ioOoYtgQfd7y7vnTakPmMa0BVnQwt V6Ez+UPu90b65JvhY7QVhUNjKj3hH8ELkOt5/iLb9tNrivw2Y65072TyWA1AvwZ5Znb0 ClXQ== X-Gm-Message-State: ALQs6tA40Tv7f8XeL8pTEkI2t6eQcaa/wpYRgcu2QDQDk33DVkuIo4ON +af47eqMKkfWKOBbCCHqRwQZWQ== X-Google-Smtp-Source: AIpwx481Qy5CcPvCc+jR6H1j0K2PMn9PuIFhQFpR7SUqtlygFDbX0coiEjzzgfswJaffC1lDA8qMtw== X-Received: by 2002:a17:902:d90e:: with SMTP id c14-v6mr1586482plz.352.1523094651456; Sat, 07 Apr 2018 02:50:51 -0700 (PDT) Received: from gmail.com (cpe-98-150-136-16.hawaii.res.rr.com. [98.150.136.16]) by smtp.gmail.com with ESMTPSA id y14sm20950995pfe.172.2018.04.07.02.50.49 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 07 Apr 2018 02:50:50 -0700 (PDT) Date: Fri, 6 Apr 2018 23:50:38 -1000 From: Joey Pabalinas To: linux-sparse@vger.kernel.org Cc: Kees Cook , Linus Torvalds , Martin Uecker , Al Viro , Luc Van Oostenryck , Christopher Li , Joey Pabalinas Subject: [PATCH] add sparse flag to toggle sizeof(void) warnings Message-ID: <20180407095038.jlfcpdez3fup3wfy@gmail.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: NeoMutt/20180323 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 Recent changes to the min()/max() macros in include/linux/kernel.h have added a lot of noise to sparse output; this is due to the *huge* number of new sizeof(void) warnings, most of which can largely be ignored. Add the -Wsizeof_void flag to enable/disable these warnings on demand; the warning itself has been disabled by default to reduce the large influx of noise which was inadvertently added by commit 3c8ba0d61d04ced9f8 (kernel.h: Retain constant expression output for max()/min()). Update the manpage to document the new flag. CC: Kees Cook CC: Linus Torvalds CC: Martin Uecker CC: Al Viro CC: Luc Van Oostenryck CC: Christopher Li Signed-off-by: Joey Pabalinas 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/evaluate.c b/evaluate.c index b96696d3a51396800a..33e5fcabc4e755e0b7 100644 --- a/evaluate.c +++ b/evaluate.c @@ -2169,7 +2169,8 @@ static struct symbol *evaluate_sizeof(struct expression *expr) size = type->bit_size; if (size < 0 && is_void_type(type)) { - warning(expr->pos, "expression using sizeof(void)"); + if (Wsizeof_void) + warning(expr->pos, "expression using sizeof(void)"); size = bits_in_char; } diff --git a/lib.c b/lib.c index 645132a892107512a1..35b41ad5becddf6b59 100644 --- a/lib.c +++ b/lib.c @@ -245,6 +245,7 @@ int Wptr_subtraction_blows = 0; int Wreturn_void = 0; int Wshadow = 0; int Wsizeof_bool = 0; +int Wsizeof_void = 0; int Wtautological_compare = 0; int Wtransparent_union = 0; int Wtypesign = 0; @@ -536,6 +537,7 @@ static const struct warning { { "return-void", &Wreturn_void }, { "shadow", &Wshadow }, { "sizeof-bool", &Wsizeof_bool }, + { "sizeof-void", &Wsizeof_void }, { "sparse-error", &Wsparse_error }, { "tautological-compare", &Wtautological_compare }, { "transparent-union", &Wtransparent_union }, diff --git a/lib.h b/lib.h index a9b70b07686801305c..517f933e97d504f2bb 100644 --- a/lib.h +++ b/lib.h @@ -138,6 +138,7 @@ extern int Wptr_subtraction_blows; extern int Wreturn_void; extern int Wshadow; extern int Wsizeof_bool; +extern int Wsizeof_void; extern int Wtautological_compare; extern int Wtransparent_union; extern int Wtypesign; diff --git a/sparse.1 b/sparse.1 index e183204de623efd022..09eecf9cbb06b9acc4 100644 --- a/sparse.1 +++ b/sparse.1 @@ -323,7 +323,25 @@ Sparse does not issue these warnings by default. .B \-Wsizeof-bool Warn when checking the sizeof a _Bool. -C99 does not specify the sizeof a _Bool. gcc uses 1. +C99 does not specify the sizeof a _Bool. GCC uses \fI1\fR. + +Sparse does not issue these warnings by default. +. +.TP +.B \-Wsizeof-void +Warn when checking the sizeof a void. + +C99 does not allow the sizeof operator to be applied to incomplete types +such as void. GCC allows \fBsizeof(void)\fR as an extension and uses \fI1\fR. + +Although non-standard, \fBsizeof(void)\fR is often useful when the intent +is to operate on an expression without evaluating it, e.g. in the following +integer constant expression predicate: + +.nf +#define __is_constexpr(x) \\ + (sizeof(int) == sizeof(*(8 ? ((void *)((long)(x) * 0l)) : (int *)8))) +.fi Sparse does not issue these warnings by default. .