public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Nathan Chancellor <nathan@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
	Kees Cook <kees@kernel.org>, Petr Mladek <pmladek@suse.com>,
	Sergey Senozhatsky <senozhatsky@chromium.org>,
	Steven Rostedt <rostedt@goodmis.org>,
	John Ogness <john.ogness@linutronix.de>,
	Rasmus Villemoes <linux@rasmusvillemoes.dk>,
	Peter Zijlstra <peterz@infradead.org>,
	linux-kernel@vger.kernel.org
Subject: Re: [GIT PULL] more printk for 6.15
Date: Thu, 3 Apr 2025 15:07:09 +0300	[thread overview]
Message-ID: <Z-557YrwVr8bONq4@smile.fi.intel.com> (raw)
In-Reply-To: <20250402203422.GA655609@ax162>

On Wed, Apr 02, 2025 at 01:34:22PM -0700, Nathan Chancellor wrote:
> On Wed, Apr 02, 2025 at 10:25:46PM +0300, Andy Shevchenko wrote:
> > +Cc: Kees and Nathan (I believe this discussion has some material for
> > you, folks, to think of / comment on / etc)
> 
> Thanks, I have commented on the part of the message that seem relevant
> for me.

Thank you!

> > On Wed, Apr 2, 2025 at 10:06 PM Linus Torvalds
> > <torvalds@linux-foundation.org> wrote:
> > > On Wed, 2 Apr 2025 at 11:39, Andy Shevchenko <andy.shevchenko@gmail.com> wrote:
> > > >
> > > > Yes. Clang complains on unknown pragma.
> > >
> > > What a crock.
> > >
> > > It says GCC, for chrissake!
> > >
> > > And clang clearly doesn't complain about
> > >
> > > >   +#pragma GCC diagnostic push
> > > >   +#pragma GCC diagnostic pop
> > >
> > > which are *not* protected by that #ifndef __clang__ thing.
> > >
> > > So this smells like a clang bug to me.
> 
> Yes, clang implements support for '#pragma GCC' for compatability with
> existing source code:
> 
> https://clang.llvm.org/docs/UsersManual.html#controlling-diagnostics-via-pragmas
> 
> Otherwise, the pragma would need to be duplicated if the warning was
> shared between the compilers (as many are nowadays).
> 
> It complains specifically about an unknown warning being passed to
> 'diagnostic ignored':
> 
>   lib/vsprintf.c:1703:32: error: unknown warning group '-Wsuggest-attribute=format', ignored [-Werror,-Wunknown-warning-option]
>    1703 | #pragma GCC diagnostic ignored "-Wsuggest-attribute=format"
>         |                                ^
>   1 error generated.
> 
> Which I suppose you could argue is a bug since it is a GCC pragma,
> although warning on an unknown option to the ignored diagnostic pragma
> is what GCC does as well (it just ignores '#pragma clang' altogether):
> 
>   $ echo '#pragma GCC diagnostic ignored "-Wfoo"' | gcc -fsyntax-only -x c -
>   <stdin>:1:32: warning: unknown option after ‘#pragma GCC diagnostic’ kind [-Wpragmas]
> 
> I can look into filing a report upstream about this, however...
> 
> > > Can we please use wrapper defines instead so that we don't have that
> > > #ifndef in the middle of code? And since those don't work with
> > > '#pragma', they need to use the _Pragma() operator instead.
> > >
> > > Something like
> > >
> > >    #define GCC_PRAGMA(x) _Pragma(#x)
> > >
> > > in compiler-gcc.h, and then add a
> > >
> > >   #ifndef GCC_PRAGMA
> > >     #define GCC_PRAGMA(x) /* Nothing */
> > >   #endif
> > >
> > > and then you can just do
> > >
> > >    GCC_PRAGMA(Wsuggest-attribute=format)
> > >
> > > in places like this?
> > >
> > > (Entirely untested: I *despise* pragma in general).
> 
> We have the __diag() infrastructure for this already. I think this issue
> would be as simple as the following diff, which makes clang and GCC
> happy without any obvious ifdeffery.

FWIW, I have tested this in my case for both compilers and they are happy with it.

Tested-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

> diff --git a/include/linux/compiler-igcc.h b/include/linux/compiler-gcc.h
> index 32048052c64a..5d07c469b571 100644
> --- a/include/linux/compiler-gcc.h
> +++ b/include/linux/compiler-gcc.h
> @@ -127,6 +127,8 @@
>  #define __diag_GCC_8(s)
>  #endif
>  
> +#define __diag_GCC_all(s)	__diag(s)
> +
>  #define __diag_ignore_all(option, comment) \
>  	__diag(__diag_GCC_ignore option)
>  
> diff --git a/lib/vsprintf.c b/lib/vsprintf.c
> index 01699852f30c..6ff4d85e144e 100644
> --- a/lib/vsprintf.c
> +++ b/lib/vsprintf.c
> @@ -1699,10 +1699,8 @@ char *escaped_string(char *buf, char *end, u8 *addr, struct printf_spec spec,
>  	return buf;
>  }
>  
> -#pragma GCC diagnostic push
> -#ifndef __clang__
> -#pragma GCC diagnostic ignored "-Wsuggest-attribute=format"
> -#endif
> +__diag_push();
> +__diag_ignore(GCC, all, "-Wsuggest-attribute=format", "<reason>");
>  static char *va_format(char *buf, char *end, struct va_format *va_fmt,
>  		       struct printf_spec spec)
>  {
> @@ -1717,7 +1715,7 @@ static char *va_format(char *buf, char *end, struct va_format *va_fmt,
>  
>  	return buf;
>  }
> -#pragma GCC diagnostic pop
> +__diag_pop();
>  
>  static noinline_for_stack
>  char *uuid_string(char *buf, char *end, const u8 *addr,

-- 
With Best Regards,
Andy Shevchenko



  reply	other threads:[~2025-04-03 12:07 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-02 12:58 [GIT PULL] more printk for 6.15 Petr Mladek
2025-04-02 17:12 ` Linus Torvalds
2025-04-02 18:39   ` Andy Shevchenko
2025-04-02 19:06     ` Linus Torvalds
2025-04-02 19:25       ` Andy Shevchenko
2025-04-02 20:34         ` Nathan Chancellor
2025-04-03 12:07           ` Andy Shevchenko [this message]
2025-04-04  8:19             ` Petr Mladek
2025-04-04 21:02               ` Nathan Chancellor
2025-04-03 16:14         ` Kees Cook
2025-04-02 19:07     ` Linus Torvalds
2025-04-02 19:10       ` Linus Torvalds
2025-04-02 19:44         ` Steven Rostedt
2025-04-02 19:52           ` Linus Torvalds
2025-04-02 20:25           ` Andy Shevchenko
2025-04-02 20:00         ` Sean Christopherson
2025-04-02 20:11           ` Steven Rostedt
2025-04-03  9:34         ` Petr Mladek
2025-04-02 17:48 ` pr-tracker-bot

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=Z-557YrwVr8bONq4@smile.fi.intel.com \
    --to=andriy.shevchenko@linux.intel.com \
    --cc=john.ogness@linutronix.de \
    --cc=kees@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@rasmusvillemoes.dk \
    --cc=nathan@kernel.org \
    --cc=peterz@infradead.org \
    --cc=pmladek@suse.com \
    --cc=rostedt@goodmis.org \
    --cc=senozhatsky@chromium.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