From: Johannes Berg <johannes@sipsolutions.net>
To: James Hogan <james.hogan@imgtec.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
linux-kernel@vger.kernel.org,
Peter Zijlstra <peterz@infradead.org>,
Daniel Santos <daniel.santos@pobox.com>,
"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>,
linux-next <linux-next@vger.kernel.org>,
linux-metag <linux-metag@vger.kernel.org>
Subject: Re: [PATCH] compiler.h: don't use temporary variable in __compiletime_assert()
Date: Tue, 13 May 2014 11:26:24 +0200 [thread overview]
Message-ID: <1399973184.4137.8.camel@jlt4.sipsolutions.net> (raw)
In-Reply-To: <5371DD92.5080304@imgtec.com>
Hi James,
> Subject: [PATCH] compiler.h: avoid sparse errors in
> __compiletime_error_fallback()
>
> Usually, BUG_ON and friends aren't even evaluated in sparse, but
> recently compiletime_assert_atomic_type() was added, and that now
> results in a sparse warning every time it is used.
>
> The reason turns out to be the temporary variable, after it sparse no
> longer considers the value to be a constant, and results in a warning
> and an error. The error is the more annoying part of this as it
> suppresses any further warnings in the same file, hiding other problems.
>
> Unfortunately the condition cannot be simply expanded out to avoid the
> temporary variable since it breaks compiletime_assert on old versions of
> GCC such as GCC 4.2.4 which the latest metag compiler is based on.
>
> Therefore #ifndef __CHECKER__ out the __compiletime_error_fallback which
> uses the potentially negative size array to trigger a conditional
> compiler error, so that sparse doesn't see it.
>
> Signed-off-by: James Hogan <james.hogan@imgtec.com>
> Cc: Johannes Berg <johannes.berg@intel.com>
> Cc: Daniel Santos <daniel.santos@pobox.com>
> Cc: Luciano Coelho <luciano.coelho@intel.com>
> Cc: Peter Zijlstra <peterz@infradead.org>
> Cc: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
> Cc: Andrew Morton <akpm@linux-foundation.org>
Acked-by: Johannes Berg <johannes@sipsolutions.net>
> It's not particularly pretty, if you can think of a better solution that
> doesn't break old GCC I'm all ears.
> #ifndef __compiletime_error
> # define __compiletime_error(message)
> -# define __compiletime_error_fallback(condition) \
> +/*
> + * Sparse complains of variable sized arrays due to the temporary variable in
> + * __compiletime_assert. Unfortunately we can't just expand it out to make
> + * sparse see a constant array size without breaking compiletime_assert on old
> + * versions of GCC (e.g. 4.2.4), so hide the array from sparse altogether.
> + */
> +# ifndef __CHECKER__
> +# define __compiletime_error_fallback(condition) \
> do { ((void)sizeof(char[1 - 2 * condition])); } while (0)
> -#else
> +# endif
> +#endif
> +#ifndef __compiletime_error_fallback
> # define __compiletime_error_fallback(condition) do { } while (0)
> #endif
That's pretty much what I had in mind, I may have expressed it a bit
differently but the end result is the same.
Thanks,
johannes
prev parent reply other threads:[~2014-05-13 9:26 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <1399530685-7749-1-git-send-email-johannes@sipsolutions.net>
2014-05-12 13:42 ` [PATCH] compiler.h: don't use temporary variable in __compiletime_assert() James Hogan
2014-05-12 14:38 ` Johannes Berg
2014-05-12 14:56 ` James Hogan
2014-05-12 21:16 ` Andrew Morton
2014-05-13 7:31 ` Johannes Berg
2014-05-13 8:53 ` James Hogan
2014-05-13 9:26 ` Johannes Berg [this message]
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=1399973184.4137.8.camel@jlt4.sipsolutions.net \
--to=johannes@sipsolutions.net \
--cc=akpm@linux-foundation.org \
--cc=daniel.santos@pobox.com \
--cc=james.hogan@imgtec.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-metag@vger.kernel.org \
--cc=linux-next@vger.kernel.org \
--cc=paulmck@linux.vnet.ibm.com \
--cc=peterz@infradead.org \
/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