Received: by 10.213.65.68 with SMTP id h4csp1340165imn; Sun, 8 Apr 2018 01:01:13 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+IQh+QJiLyzAiHCm1gMiJuooHyzLBeb78hWXy6HGYPbkdiUcCVH1w1obd2YSx0HUIlodiV X-Received: by 2002:a17:902:6bca:: with SMTP id m10-v6mr34314374plt.387.1523174473148; Sun, 08 Apr 2018 01:01:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523174473; cv=none; d=google.com; s=arc-20160816; b=hjZZROIpkDA8gAulw1KS2wOjduLrOh9DVhW6gjekjGrvBHSdx51814zkTt2ah0PaC7 ROF97uziEm/5NZycYoJJ/VMsz/tRDPIC/V5p8shvU41d9cjqt9vt8iaL6KY4AAOuHAmU ga6yJ+Tnmu/yF3U7OQSvYQAOOXc5SbnS8PMMYIm5hIeP0WME2iIRFWYg8NTUCScFjZm9 8QdltOX0REUF6pe8YesUtKwCb2TF+o5bOWoky40qDPqQ+PPM/pBoR94Klvu9qJaMZiDO E7SlJKIJQpDFqR1YLk2s5IigxrKtiFn9OO0XNOGNcwkoVEDJ3I2rZnUrr0au9CVXhIik +pmA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=0kt3DSsqC6lD3usehs1Gh2qzIe/0waQqXIjFrxqT/GY=; b=uj7dPt6LIQ25/JoBNiMzCT5gpsFc3rk/n98NyGv51pPtxO8lqfGXMuRagH9sHrOsYm oJ84NZJ18qwcMReLCAlTaZA8IPRnJjI/46i+ya5nNT5Jr1zN2udhsUOTZKvYIgVdVEW0 UXepDOvtGM1PHHOUDAY+BiNjLY1gKFOAQTML/KEmCJEw6OIcjWHOrJ8CZP+/mgapbk7W b7S2yyoWXYKV+03+0hRSGVL9N018XcsAIpbYTc2HS3k1AAgyBSetTrpUzumhAnxnba06 SRttKCE5x5FewZE6H0dqGJ4OuNogCYBqzw/1DFBkhiR1Zqs7tSkyzE2oty+8ef6pcWVJ oWpg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=hGM3Ea+b; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k3-v6si12038642pld.221.2018.04.08.01.00.02; Sun, 08 Apr 2018 01:01:13 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=hGM3Ea+b; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752052AbeDHHsb (ORCPT + 99 others); Sun, 8 Apr 2018 03:48:31 -0400 Received: from mail-wm0-f45.google.com ([74.125.82.45]:37463 "EHLO mail-wm0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751641AbeDHHsa (ORCPT ); Sun, 8 Apr 2018 03:48:30 -0400 Received: by mail-wm0-f45.google.com with SMTP id r131so9793540wmb.2; Sun, 08 Apr 2018 00:48:29 -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:references:mime-version :content-disposition:in-reply-to:user-agent; bh=0kt3DSsqC6lD3usehs1Gh2qzIe/0waQqXIjFrxqT/GY=; b=hGM3Ea+b5IxAcHgSZ2DnyTEV4273TZZhyb+F2uaFBV0NgZtDpm4kke9JSakgzwfHCz f9Setw5Hv8l0EHdDGZBf/BoG085bKvzw9Ilt2hx5O6GdDe3WKdDYwrcPCTLYEiuOOWrg FyIy0cHZPp4CztNr438ayHkSdQXnJvkwl394Yl+5sMrwsteLHqpDX/LqBeVdfdSkgKiW vuCnmZd8yOyNmDC/rmGDSKMPLnRx02RrMdBZzzpk1mZEQ5d/yEf9nkahRN2aLkcvXvEE gszgvm+Y0IYt0dCuEC1Nw6NW7FEGvw13CNMps7/bcG9GwjSQOYbmc83ImJ2zNQEBqQkf jmMg== 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:references :mime-version:content-disposition:in-reply-to:user-agent; bh=0kt3DSsqC6lD3usehs1Gh2qzIe/0waQqXIjFrxqT/GY=; b=eX/jwCzozwWZGc5/2V6I6GN64+qlsjI0Kxu/38X7lTeXA4q6ggjHs8EioVQXHR/Y8n jkkWGmyHyTVF/MF8TCDmZNsxUdRXxLt7HbkiluQoLF4oUzR9ovwMwM8VlgotTrLdDaqH eh3z5R+FWNuJI9g+n0U9/KAnOQtRpumSsQxZ/qMTo5PWMjsGn65qkBemW2yO+ocnEzzt I12zacU30clWZ4RQ+5LjRqj3d5SWYgaD74qjp5iMiPaOcMW/0jOL4QbhuVhM3+8y+0+g pn1AoE/cdmmgLfMYFhh6bqBV+rxyPU/i8/zWdp0oXdkmUUbccRFlq4tSkHAhkfsnGqfC Ougg== X-Gm-Message-State: ALQs6tCor0VqhUQCiLxxWL3VSIrTcun1cVH/NxLFsf0o1VeiWDo12oDc l1lY2O/d88iEWJvvjuG12ZY= X-Received: by 10.80.179.236 with SMTP id t41mr16074394edd.40.1523173708874; Sun, 08 Apr 2018 00:48:28 -0700 (PDT) Received: from ltop.local ([2a02:a03f:4067:9400:d571:864e:1851:830a]) by smtp.gmail.com with ESMTPSA id j15sm8745802edj.42.2018.04.08.00.48.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 08 Apr 2018 00:48:28 -0700 (PDT) Date: Sun, 8 Apr 2018 09:48:24 +0200 From: Luc Van Oostenryck To: Joey Pabalinas Cc: linux-sparse@vger.kernel.org, Kees Cook , Linus Torvalds , Martin Uecker , Al Viro , Christopher Li , Linux Kernel Mailing List Subject: Re: [PATCH v2] add -Wpointer-arith sparse flag to toggle sizeof(void) warnings Message-ID: <20180408074823.fgrmtrjzzjb7dlt2@ltop.local> References: <20180407215805.ze5rx4v3slbjngmo@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180407215805.ze5rx4v3slbjngmo@gmail.com> User-Agent: NeoMutt/20171215 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Apr 07, 2018 at 11:58:05AM -1000, Joey Pabalinas wrote: > Recent changes to the min()/max() macros in include/linux/kernel.h > have added a lot of noise when compiling the kernel with Sparse checking > enabled. This mostly is due to the *huge* increase in the number of > sizeof(void) warnings, a larger number of which can safely be ignored. > > Add the -Wpointer-arith flag to enable/disable these warnings (along > with the warning when applying sizeof to function types exactly like the > GCC -Wpointer-arith flag) 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()). Thanks. It's good to me. I just have a few remarks/suggestions: With the warning disabled by default (for the moment), I had to adapt the testsuite with: diff --git a/validation/sizeof-function.c b/validation/sizeof-function.c index 27d535d4e..8ff67f214 100644 --- a/validation/sizeof-function.c +++ b/validation/sizeof-function.c @@ -35,7 +35,7 @@ int test(void) /* * check-name: sizeof-function - * check-command: sparse -Wno-decl $file + * check-command: sparse -Wpointer-arith -Wno-decl $file * * check-error-start sizeof-function.c:22:14: warning: expression using sizeof on a function > diff --git a/sparse.1 b/sparse.1 > index 88343f3170f195297a..4379406999c94b806e 100644 > --- a/sparse.1 > +++ b/sparse.1 > @@ -288,6 +288,25 @@ Standard C syntax does not permit a parenthesized string as an array > initializer. GCC allows this syntax as an extension. With > \fB\-Wparen\-string\fR, Sparse will warn about this syntax. > > +Sparse does not issue these warnings by default. > +. > +.TP > +.B \-Wpointer-arith > +Warn about anything that depends on the \fBsizeof\fR a function type or of void. Maybe it would be useful to add something along the line of "like directly using the sizeof operator on void or doing pointer arithmetic on a void pointer" ? > +Although non-standard (and somewhat illogical), constructs such as \fBsizeof(void)\fR > +are 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 I think that pointer arithmetic is much more useful than taking the size of void (being able to take the size of *any* thing is somewhere in the middle, IMO). But in all case, I don't think this part should belong to the man page. Cheers, -- Luc