public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Tom Rini <trini@konsulko.com>
To: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
Cc: u-boot@lists.denx.de, Stefan Roese <sr@denx.de>,
	Matt Merhar <mattmerhar@protonmail.com>,
	Simon Glass <sjg@chromium.org>
Subject: Re: [RFC PATCH 1/2] build_bug.h: add wrapper for _Static_assert
Date: Thu, 1 Jul 2021 17:54:49 -0400	[thread overview]
Message-ID: <20210701215449.GR9516@bill-the-cat> (raw)
In-Reply-To: <20210518091947.63513-2-rasmus.villemoes@prevas.dk>

[-- Attachment #1: Type: text/plain, Size: 1408 bytes --]

On Tue, May 18, 2021 at 11:19:46AM +0200, Rasmus Villemoes wrote:

> [Linux commit 6bab69c65013bed5fce9f101a64a84d0385b3946]
> 
> BUILD_BUG_ON() is a little annoying, since it cannot be used outside
> function scope.  So one cannot put assertions about the sizeof() a
> struct next to the struct definition, but has to hide that in some more
> or less arbitrary function.
> 
> Since gcc 4.6 (which is now also the required minimum), there is support
> for the C11 _Static_assert in all C modes, including gnu89.  So add a
> simple wrapper for that.
> 
> _Static_assert() requires a message argument, which is usually quite
> redundant (and I believe that bug got fixed at least in newer C++
> standards), but we can easily work around that with a little macro
> magic, making it optional.
> 
> For example, adding
> 
>   static_assert(sizeof(struct printf_spec) == 8);
> 
> in vsprintf.c and modifying that struct to violate it, one gets
> 
> ./include/linux/build_bug.h:78:41: error: static assertion failed: "sizeof(struct printf_spec) == 8"
>  #define __static_assert(expr, msg, ...) _Static_assert(expr, "" msg "")
> 
> godbolt.org suggests that _Static_assert() has been support by clang
> since at least 3.0.0.
> 
> Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
> Reviewed-by: Simon Glass <sjg@chromium.org>

Applied to u-boot/next, thanks!

-- 
Tom

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 659 bytes --]

  parent reply	other threads:[~2021-07-01 21:55 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-17 17:32 [PATCH] powerpc: fix regression in arch_initr_trap() Matt Merhar
2021-05-18  5:50 ` Stefan Roese
2021-05-18  7:04   ` Rasmus Villemoes
2021-05-18  9:19     ` [RFC PATCH 0/2] sizeof(gd_t) sanity checking Rasmus Villemoes
2021-05-18  9:19       ` [RFC PATCH 1/2] build_bug.h: add wrapper for _Static_assert Rasmus Villemoes
2021-05-19 15:34         ` Simon Glass
2021-07-01 21:54         ` Tom Rini [this message]
2021-05-18  9:19       ` [RFC PATCH 2/2] global-data.h: add build-time sanity check of sizeof(struct global_data) Rasmus Villemoes
2021-05-19 15:34         ` Simon Glass
2021-07-01 21:54         ` Tom Rini
2021-06-03 13:38       ` [PATCH 1/4] powerpc: Don't use relative include for config.h in global_data.h Tom Rini
2021-06-03 13:39         ` [PATCH 2/4] Revert "powerpc: fix regression in arch_initr_trap()" Tom Rini
2021-06-24 13:15           ` Tom Rini
2021-06-03 13:39         ` [PATCH 3/4] socfpga64: Do not define CONFIG_SYS_MEM_RESERVE_SECURE to 0 Tom Rini
2021-06-03 15:07           ` Rasmus Villemoes
2021-06-03 15:14             ` Tom Rini
2021-06-24 13:15           ` Tom Rini
2021-06-03 13:39         ` [PATCH 4/4] global_data: Ensure we have <config.h> when symbols are not in Kconfig yet Tom Rini
2021-06-24 13:15           ` Tom Rini
2021-06-05 19:18         ` [PATCH 1/4] powerpc: Don't use relative include for config.h in global_data.h Matt Merhar
2021-06-24 13:15         ` Tom Rini
2021-05-27 11:42 ` [PATCH] powerpc: fix regression in arch_initr_trap() Tom Rini

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=20210701215449.GR9516@bill-the-cat \
    --to=trini@konsulko.com \
    --cc=mattmerhar@protonmail.com \
    --cc=rasmus.villemoes@prevas.dk \
    --cc=sjg@chromium.org \
    --cc=sr@denx.de \
    --cc=u-boot@lists.denx.de \
    /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