From: Konstantin Khlebnikov <khlebnikov@openvz.org>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"linux-arch@vger.kernel.org" <linux-arch@vger.kernel.org>,
Hugh Dickins <hughd@google.com>
Subject: Re: [PATCH 1/4] compiler.h: introduce unused_expression() macro
Date: Fri, 27 Apr 2012 11:54:37 +0400 [thread overview]
Message-ID: <4F9A50BD.1090000@openvz.org> (raw)
In-Reply-To: <20120426153411.8686e0f9.akpm@linux-foundation.org>
Andrew Morton wrote:
> On Wed, 25 Apr 2012 15:26:23 +0400
> Konstantin Khlebnikov<khlebnikov@openvz.org> wrote:
>
>> Sometimes we want to check some expressions correctness in compile-time without
>> generating extra code. "(void)(e)" does not work if expression has side-effects.
>> This patch introduces macro unused_expression() which helps in this situation.
>>
>> Cast to "long" required because sizeof does not work for bit-fields.
>>
>> Signed-off-by: Konstantin Khlebnikov<khlebnikov@openvz.org>
>> ---
>> include/linux/compiler.h | 2 ++
>> 1 file changed, 2 insertions(+)
>>
>> diff --git a/include/linux/compiler.h b/include/linux/compiler.h
>> index 923d093..46fbda3 100644
>> --- a/include/linux/compiler.h
>> +++ b/include/linux/compiler.h
>> @@ -310,4 +310,6 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
>> */
>> #define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
>>
>> +#define unused_expression(e) ((void)(sizeof((__force long)(e))))
>> +
>
> btw, please let's not add undocumented stuff, particularly obscure
> undocumented stuff.
>
> I typed this in:
Thanks!
>
> --- a/include/linux/compiler.h~compilerh-introduce-unused_expression-macro-fix
> +++ a/include/linux/compiler.h
> @@ -310,6 +310,11 @@ void ftrace_likely_update(struct ftrace_
> */
> #define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
>
> +/*
> + * unused_expression() permits the compiler to check the validity of the
> + * expression but avoids the generation of any code, even if that expression
> + * has side-effects.
> + */
> #define unused_expression(e) ((void)(sizeof((__force long)(e))))
>
> #endif /* __LINUX_COMPILER_H */
>
> but then decided I didn't want to apply the patches (yet?).
I'm OK with that. But probably Hugh Dickins (now in CC) aggressively wants to
remove side-effects of VM_BUG_ON's in case CONFIG_DEBUG_VM=n
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/
next prev parent reply other threads:[~2012-04-27 7:54 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-04-25 11:26 [PATCH 1/4] compiler.h: introduce unused_expression() macro Konstantin Khlebnikov
2012-04-25 11:26 ` [PATCH 2/4] bug: completely remove code of disabled VM_BUG_ON() Konstantin Khlebnikov
2012-04-25 14:40 ` Geert Uytterhoeven
2012-04-26 22:32 ` Andrew Morton
2012-04-27 5:17 ` Geert Uytterhoeven
2012-04-27 7:07 ` Andrew Morton
2012-04-25 11:26 ` [PATCH 3/4] bug: completely remove code of disabled BUG_ON() Konstantin Khlebnikov
2012-04-25 11:26 ` Konstantin Khlebnikov
2012-04-25 11:26 ` [PATCH 4/4] bug: mark disabled BUG() as unreachable() code Konstantin Khlebnikov
2012-04-25 11:26 ` Konstantin Khlebnikov
2012-04-28 5:10 ` Konstantin Khlebnikov
2012-04-28 5:21 ` Linus Torvalds
2012-04-28 5:21 ` Linus Torvalds
2012-04-28 6:14 ` Andrew Morton
2012-04-25 11:51 ` [PATCH 1/4] compiler.h: introduce unused_expression() macro Cong Wang
2012-04-25 11:54 ` Konstantin Khlebnikov
2012-04-25 11:54 ` Konstantin Khlebnikov
2012-04-26 22:29 ` Andrew Morton
2012-04-27 9:55 ` Konstantin Khlebnikov
2012-04-27 21:53 ` Andrew Morton
2012-04-26 22:34 ` Andrew Morton
2012-04-26 22:34 ` Andrew Morton
2012-04-27 7:54 ` Konstantin Khlebnikov [this message]
2012-04-27 8:16 ` H. Peter Anvin
2012-04-28 3:50 ` Konstantin Khlebnikov
2012-04-28 3:50 ` Konstantin Khlebnikov
2012-04-28 7:06 ` [PATCH v2 1/2] bug: introduce BUILD_BUG_ON_INVALID() macro Konstantin Khlebnikov
2012-04-28 7:06 ` Konstantin Khlebnikov
2012-04-28 7:06 ` [PATCH v2 2/2] bug: completely remove code of disabled VM_BUG_ON() Konstantin Khlebnikov
2012-04-28 7:06 ` Konstantin Khlebnikov
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=4F9A50BD.1090000@openvz.org \
--to=khlebnikov@openvz.org \
--cc=akpm@linux-foundation.org \
--cc=hughd@google.com \
--cc=linux-arch@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=torvalds@linux-foundation.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;
as well as URLs for NNTP newsgroup(s).