public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH] MdePkg/DebugLib; swap if conditions in ASSERT_[EFI|RETURN]_ERROR
@ 2017-12-07 15:12 Ard Biesheuvel
  2017-12-07 15:26 ` Ard Biesheuvel
  0 siblings, 1 reply; 11+ messages in thread
From: Ard Biesheuvel @ 2017-12-07 15:12 UTC (permalink / raw)
  To: edk2-devel
  Cc: leif.lindholm, liming.gao, evan.lloyd, michael.d.kinney,
	Alexei.Fedorov, Ard Biesheuvel

ASSERT_EFI_ERROR () is currently defined as

  #if !defined(MDEPKG_NDEBUG)
    #define ASSERT_EFI_ERROR(StatusParameter)                                              \
      do {                                                                                 \
        if (DebugAssertEnabled ()) {                                                       \
          if (EFI_ERROR (StatusParameter)) {                                               \
            DEBUG ((EFI_D_ERROR, "\nASSERT_EFI_ERROR (Status = %r)\n", StatusParameter));  \
            _ASSERT (!EFI_ERROR (StatusParameter));                                        \
          }                                                                                \
        }                                                                                  \
      } while (FALSE)
  #else
    #define ASSERT_EFI_ERROR(StatusParameter)
  #endif

This is suboptimal, given that the DebugAssertEnabled () call in the
outer if must be executed unconditionally, since the compiler does not
know that it does not have any side effects. Instead, let's swap the
two ifs, and only call DebugAssertEnabled () if StatusParameter contains
an error value to begin with. Do the same for ASSERT_RETURN_ERROR
as well.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Reported-by: Alexei Fedorov <Alexei.Fedorov@arm.com>
---
 MdePkg/Include/Library/DebugLib.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/MdePkg/Include/Library/DebugLib.h b/MdePkg/Include/Library/DebugLib.h
index 3a910e6a208b..8369c378e79c 100644
--- a/MdePkg/Include/Library/DebugLib.h
+++ b/MdePkg/Include/Library/DebugLib.h
@@ -337,8 +337,8 @@ DebugPrintLevelEnabled (
 #if !defined(MDEPKG_NDEBUG)
   #define ASSERT_EFI_ERROR(StatusParameter)                                              \
     do {                                                                                 \
-      if (DebugAssertEnabled ()) {                                                       \
-        if (EFI_ERROR (StatusParameter)) {                                               \
+      if (EFI_ERROR (StatusParameter)) {                                                 \
+        if (DebugAssertEnabled ()) {                                                     \
           DEBUG ((EFI_D_ERROR, "\nASSERT_EFI_ERROR (Status = %r)\n", StatusParameter));  \
           _ASSERT (!EFI_ERROR (StatusParameter));                                        \
         }                                                                                \
@@ -363,8 +363,8 @@ DebugPrintLevelEnabled (
 #if !defined(MDEPKG_NDEBUG)
   #define ASSERT_RETURN_ERROR(StatusParameter)                          \
     do {                                                                \
-      if (DebugAssertEnabled ()) {                                      \
-        if (RETURN_ERROR (StatusParameter)) {                           \
+      if (RETURN_ERROR (StatusParameter)) {                             \
+        if (DebugAssertEnabled ()) {                                    \
           DEBUG ((DEBUG_ERROR, "\nASSERT_RETURN_ERROR (Status = %r)\n", \
             StatusParameter));                                          \
           _ASSERT (!RETURN_ERROR (StatusParameter));                    \
-- 
2.11.0



^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2017-12-07 20:38 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-12-07 15:12 [PATCH] MdePkg/DebugLib; swap if conditions in ASSERT_[EFI|RETURN]_ERROR Ard Biesheuvel
2017-12-07 15:26 ` Ard Biesheuvel
2017-12-07 17:01   ` Kinney, Michael D
2017-12-07 17:09     ` Ard Biesheuvel
2017-12-07 17:13       ` Ard Biesheuvel
2017-12-07 17:36         ` Kinney, Michael D
2017-12-07 17:43           ` Ard Biesheuvel
2017-12-07 19:49             ` Kinney, Michael D
2017-12-07 19:52               ` Ard Biesheuvel
2017-12-07 20:33                 ` Kinney, Michael D
2017-12-07 20:42                   ` Ard Biesheuvel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox