mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Willy Tarreau <w@1wt.eu>
To: "Thomas Weißschuh" <linux@weissschuh.net>
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH] tools/nolibc: compiler: add macro __nolibc_fallthrough
Date: Mon, 30 Sep 2024 05:33:57 +0200	[thread overview]
Message-ID: <20240930033357.GA13730@1wt.eu> (raw)
In-Reply-To: <20240929-nolibc-fallthrough-v1-1-5ee07ea9a683@weissschuh.net>

Hi Thomas,

On Sun, Sep 29, 2024 at 11:49:57PM +0200, Thomas Weißschuh wrote:
> Recent version of GCC and clang gained -Wimplicit-fallthrough,
> warning about implicit fall-through between switch labels.
> As nolibc does not control the compilation flags, this can trigger
> warnings for when built by the user.
> Make use of the "fallthrough" attribute to explicitly annotate the
> expected fall-throughs and silence the warning.

Good idea!

> +#if __nolibc_has_attribute(fallthrough)
> +#  define __nolibc_fallthrough __attribute__((fallthrough))
> +#else
> +#  define __nolibc_fallthrough
> +#endif /* __nolibc_has_attribute(fallthrough) */

In haproxy we're prepending a "do { } while (0)" statement at the
beginning of the macro, first to make sure to have a statement for
the case where it's not supported, and because gcc-7 will emit a
warning if placed after a label (and clang will even error in this
case). I'm covering all known cases with the following:

  #if __has_attribute(fallthrough)
  #  define __fallthrough do { } while (0); __attribute__((fallthrough))
  #else
  #  define __fallthrough do { } while (0)
  #endif

I think you should do the same here since, as you mentioned, we have
no control over the user's toolchain.

Thanks,
Willy

      reply	other threads:[~2024-09-30  3:34 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-29 21:49 Thomas Weißschuh
2024-09-30  3:33 ` Willy Tarreau [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=20240930033357.GA13730@1wt.eu \
    --to=w@1wt.eu \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@weissschuh.net \
    /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®