From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f68.google.com ([74.125.82.68]:40255 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727094AbeGaBDS (ORCPT ); Mon, 30 Jul 2018 21:03:18 -0400 Date: Mon, 30 Jul 2018 16:25:54 -0700 From: Nathan Chancellor To: Nick Desaulniers Cc: akpm@linux-foundation.org, arnd@arndb.de, paul.burton@mips.com, christophe.leroy@c-s.fr, shorne@gmail.com, yamada.masahiro@socionext.com, keescook@chromium.org, mingo@kernel.org, gregkh@linuxfoundation.org, tglx@linutronix.de, rdunlap@infradead.org, bp@suse.de, neilb@suse.com, linux-kernel@vger.kernel.org, aryabinin@virtuozzo.com, dwmw@amazon.co.uk, sandipan@linux.vnet.ibm.com, linux@rasmusvillemoes.dk, paullawrence@google.com, andreyknvl@google.com, will.deacon@arm.com, ghackmann@android.com, stable@vger.kernel.org, ghackmann@google.com, mka@chromium.org, jpoimboe@redhat.com, wvw@google.com, avagin@openvz.org Subject: Re: [PATCH v2 1/2] compiler-clang.h: Add CLANG_VERSION and __diag macros Message-ID: <20180730232554.GA16996@flashbox> References: <20180730213412.242849-1-ndesaulniers@google.com> <20180730213412.242849-2-ndesaulniers@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180730213412.242849-2-ndesaulniers@google.com> Sender: stable-owner@vger.kernel.org List-ID: On Mon, Jul 30, 2018 at 02:34:11PM -0700, Nick Desaulniers wrote: > These are needed for doing proper version checks, though feature > detection via __has_attribute, __has_builtin, and __has_feature should > be preferred, see: > https://clang.llvm.org/docs/LanguageExtensions.html#feature-checking-macros > > Also adds __diag support, for generating compiler version specific > _Pragma()'s. > > __diag support based on commit 8793bb7f4a9d ("kbuild: add macro for > controlling warnings to linux/compiler.h") > > Cc: stable@vger.kernel.org # 4.17, 4.14, 4.9, 4.4 > Suggested-by: Nathan Chancellor > Signed-off-by: Nick Desaulniers Tested-and-reviewed-by: Nathan Chancellor > --- > include/linux/compiler-clang.h | 19 +++++++++++++++++++ > include/linux/compiler_types.h | 4 ++++ > 2 files changed, 23 insertions(+) > > diff --git a/include/linux/compiler-clang.h b/include/linux/compiler-clang.h > index 7087446c24c8..9442e07a361e 100644 > --- a/include/linux/compiler-clang.h > +++ b/include/linux/compiler-clang.h > @@ -7,6 +7,10 @@ > * for Clang compiler > */ > > +#define CLANG_VERSION (__clang_major__ * 10000 \ > + + __clang_minor__ * 100 \ > + + __clang_patchlevel__) > + I know this was done to be consistent with GCC_VERSION but certain toolchains may set the patch level to the SVN revision (at least that's what it appears to be) like AOSP's clang-4053586, which would make CLANG_VERSION 350080. For this particular warning, it doesn't matter since Clang has supported it since 2011 and Clang 5.0 isn't supported in this tree anyways but maybe relying on just __clang_major__ below is more ideal. Other than that, patch functions just as it should. > #ifdef uninitialized_var > #undef uninitialized_var > #define uninitialized_var(x) x = *(&(x)) > @@ -46,3 +50,18 @@ > __has_builtin(__builtin_sub_overflow) > #define COMPILER_HAS_GENERIC_BUILTIN_OVERFLOW 1 > #endif > + > +#define __diag_str1(s) #s > +#define __diag_str(s) __diag_str1(s) > +#define __diag(s) _Pragma(__diag_str(clang diagnostic s)) > +#define __diag_CLANG_ignore ignored > +#define __diag_CLANG_warn warning > +#define __diag_CLANG_error error > +#define __diag_CLANG(version, severity, s) \ > + __diag_CLANG_ ## version(__diag_CLANG_ ## severity s) > + > +#if CLANG_VERSION >= 70000 > +#define __diag_CLANG_7(s) __diag(s) > +#else > +#define __diag_CLANG_7(s) > +#endif > diff --git a/include/linux/compiler_types.h b/include/linux/compiler_types.h > index a8ba6b04152c..a04e6bd63476 100644 > --- a/include/linux/compiler_types.h > +++ b/include/linux/compiler_types.h > @@ -279,6 +279,10 @@ struct ftrace_likely_data { > #define __diag_GCC(version, severity, string) > #endif > > +#ifndef __diag_CLANG > +#define __diag_CLANG(version, severity, string) > +#endif > + > #define __diag_push() __diag(push) > #define __diag_pop() __diag(pop) > > -- > 2.18.0.345.g5c9ce644c3-goog >