mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
To: Masahiro Yamada <yamada.masahiro@socionext.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Nick Desaulniers <ndesaulniers@google.com>,
	Kees Cook <keescook@chromium.org>,
	Josh Triplett <josh@joshtriplett.org>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 3/3] build_bug.h: remove most of dummy BUILD_BUG_ON stubs for sparse
Date: Mon, 19 Nov 2018 13:37:33 +0100	[thread overview]
Message-ID: <20181119123732.zcb6axl25bixgtly@ltop.local> (raw)
In-Reply-To: <1542623503-3755-3-git-send-email-yamada.masahiro@socionext.com>

On Mon, Nov 19, 2018 at 07:31:43PM +0900, Masahiro Yamada wrote:
> The introduction of these dummy BUILD_BUG_ON stubs dates back to
> commit 903c0c7cdc21 ("sparse: define dummy BUILD_BUG_ON definition
> for sparse").
> 
> At that time, BUILD_BUG_ON() was implemented with the negative array
> trick *and* the link-time trick, like this:
> 
>   extern int __build_bug_on_failed;
>   #define BUILD_BUG_ON(condition)                                \
>           do {                                                   \
>                   ((void)sizeof(char[1 - 2*!!(condition)]));     \
>                   if (condition) __build_bug_on_failed = 1;      \
>           } while(0)
> 
> Sparse is more strict about the negative array trick than GCC because
> Sparse requires the array length to be really constant.
> 
> Here is the simple test code for the macro above:
> 
>   static const int x = 0;
>   BUILD_BUG_ON(x);
> 
> GCC is absolutely fine with it (-Wvla was not enabled at that time),
> but Sparse warns like this:
> 
>   error: bad constant expression
>   error: cannot size expression
> 
> (If you are using a newer version of Sparse, you will see a different
> warning message, "warning: Variable length array is used".)
> 
> Anyway, Sparse was producing many false positive warnings, hence
> silenced.
> 
> With the previous commit, the leftover negative array trick is gone.
> Sparse is fine with the current BUILD_BUG_ON(), which is implemented
> by using the 'error' attribute. (assuming your Sparse version supports
> -Wno-unknown-attribute option)
> 
> I am keeping the stub for BUILD_BUG_ON_ZERO(). Otherwise, Sparse
> would complain about the following code, which GCC is fine with:
> 
>   static const int x = 0;
>   int y = BUILD_BUG_ON_ZERO(x);
> 
> Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
> Acked-by: Kees Cook <keescook@chromium.org>

Reviewed-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>

  reply	other threads:[~2018-11-19 12:37 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-19 10:31 [PATCH v3 1/3] compiler_types.h: make __builtin_types_compatible_p() noop for Sparse Masahiro Yamada
2018-11-19 10:31 ` [PATCH v3 2/3] build_bug.h: remove negative-array fallback for BUILD_BUG_ON() Masahiro Yamada
2018-11-19 18:10   ` Nick Desaulniers
2018-11-19 10:31 ` [PATCH v3 3/3] build_bug.h: remove most of dummy BUILD_BUG_ON stubs for sparse Masahiro Yamada
2018-11-19 12:37   ` Luc Van Oostenryck [this message]
2018-11-19 18:00     ` Nick Desaulniers
2018-11-20  1:30       ` Masahiro Yamada
2018-11-19 12:33 ` [PATCH v3 1/3] compiler_types.h: make __builtin_types_compatible_p() noop for Sparse Luc Van Oostenryck
2018-11-20  1:32   ` Masahiro Yamada

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20181119123732.zcb6axl25bixgtly@ltop.local \
    --to=luc.vanoostenryck@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=josh@joshtriplett.org \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ndesaulniers@google.com \
    --cc=yamada.masahiro@socionext.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®