From: "Michael Brown" <mcb30@ipxe.org>
To: "Marvin Häuser" <mhaeuser@posteo.de>, devel@edk2.groups.io
Cc: michael.d.kinney@intel.com, krichanov@ispras.ru,
gaoliming@byosoft.com.cn, "Liu,
Zhiguang" <zhiguang.liu@intel.com>,
vit9696@protonmail.com
Subject: Re: [edk2-devel] [PATCH] MdePkg: DebugLib: Compilation fix for clang-13.
Date: Tue, 23 Nov 2021 11:40:31 +0000 [thread overview]
Message-ID: <5084a725-5ee1-d7cf-c662-1e4a7128e0f1@ipxe.org> (raw)
In-Reply-To: <b3510e57-b9df-4e32-b7f7-30c557ff9a28@posteo.de>
On 23/11/2021 06:41, Marvin Häuser wrote:
> 23.11.2021 00:17:30 Michael Brown <mcb30@ipxe.org>:
>> I would very strongly recommend having the non-debug version of the macro use something like:
>>
>> #define ASSERT(Expression) do { \
>> if (FALSE) { \
>> (VOID) (Expression); \
>> } \
>> } while (FALSE)
>>
>> Without the "if (FALSE)", you will find that an expression that may have side-effects (e.g. by calling an external function) will result in executable code being generated.
>
> In theory +1, but don't some compilers generate "unreachable code" warnings for this? I unfortunately cannot check them all right now. Maybe guards push/pop'ing the warning for that need to be defined, that are only allowed to be used with explicit documentation why they are necessary?
A quick experiment shows that gcc won't generate a warning but clang
will. Can be fixed by adding extra parentheses around FALSE:
#define ASSERT(Expression) do { \
if ((FALSE)) { \
(VOID) (Expression); \
} \
} while (FALSE)
which is still clean and relatively elegant.
Thanks,
Michael
prev parent reply other threads:[~2021-11-23 11:40 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20211119090529.2865-1-krichanov@ispras.ru>
2021-11-19 16:51 ` [PATCH] MdePkg: DebugLib: Compilation fix for clang-13 Michael D Kinney
[not found] ` <db6fe4e5b31c28a6bcdb1f189cfcd5b1@ispras.ru>
2021-11-22 16:42 ` Michael D Kinney
2021-11-22 23:17 ` [edk2-devel] " Michael Brown
2021-11-23 6:41 ` Marvin Häuser
2021-11-23 11:40 ` Michael Brown [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-list 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=5084a725-5ee1-d7cf-c662-1e4a7128e0f1@ipxe.org \
--to=devel@edk2.groups.io \
/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