When ASSERTS are enabled, running the expression twice could have unintended 
consequences, particularly if a variable is being incremented or modified in 
some fashion.

Thomas

-----Original Message-----
From: edk2-devel [mailto:[email protected]] On Behalf Of Marvin 
Häuser
Sent: Monday, May 30, 2016 8:22 AM
To: [email protected]
Cc: [email protected]; [email protected]
Subject: [edk2] [PATCH v1 1/1] MdePkg/DebugLib: Ignore DEBUG variables in 
RELEASE builds.

When the only point of use of a variable is a DEBUG() or ASSERT() expression, 
most compilers will issue a warning when targeting RELEASE. Cast the parameters 
to VOID to silence these warnings.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Marvin Haeuser <[email protected]>
---
 MdePkg/Include/Library/DebugLib.h | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/MdePkg/Include/Library/DebugLib.h 
b/MdePkg/Include/Library/DebugLib.h
index 93b6f8df34ae..25c8ebb95740 100644
--- a/MdePkg/Include/Library/DebugLib.h
+++ b/MdePkg/Include/Library/DebugLib.h
@@ -270,7 +270,7 @@ DebugPrintLevelEnabled (
     } while (FALSE)
   #define _DEBUG(Expression)   _DEBUG_PRINT Expression
 #else
-#define _DEBUG(Expression)   DebugPrint Expression
+  #define _DEBUG(Expression)   DebugPrint Expression
 #endif
 
 /**
@@ -288,6 +288,8 @@ DebugPrintLevelEnabled (
 #if !defined(MDEPKG_NDEBUG)       
   #define ASSERT(Expression)        \
     do {                            \
+      (VOID)(Expression);           \
+                                    \
       if (DebugAssertEnabled ()) {  \
         if (!(Expression)) {        \
           _ASSERT (Expression);     \
@@ -295,7 +297,7 @@ DebugPrintLevelEnabled (
       }                             \
     } while (FALSE)
 #else
-  #define ASSERT(Expression)
+  #define ASSERT(Expression) (VOID)(Expression)
 #endif
 
 /**
@@ -312,13 +314,15 @@ DebugPrintLevelEnabled (  **/
 #if !defined(MDEPKG_NDEBUG)      
   #define DEBUG(Expression)        \
+    (VOID)(Expression);            \
+                                   \
     do {                           \
       if (DebugPrintEnabled ()) {  \
         _DEBUG (Expression);       \
       }                            \
     } while (FALSE)
 #else
-  #define DEBUG(Expression)
+  #define DEBUG(Expression) (VOID)(Expression)
 #endif
 
 /**
@@ -336,6 +340,8 @@ DebugPrintLevelEnabled (  #if !defined(MDEPKG_NDEBUG)
   #define ASSERT_EFI_ERROR(StatusParameter)                                    
          \
     do {                                                                       
          \
+      (VOID)(StatusParameter);                                                 
          \
+                                                                               
          
+ \
       if (DebugAssertEnabled ()) {                                             
          \
         if (EFI_ERROR (StatusParameter)) {                                     
          \
           DEBUG ((EFI_D_ERROR, "\nASSERT_EFI_ERROR (Status = %r)\n", 
StatusParameter));  \ @@ -344,7 +350,7 @@ DebugPrintLevelEnabled (
       }                                                                        
          \
     } while (FALSE)
 #else
-  #define ASSERT_EFI_ERROR(StatusParameter)
+  #define ASSERT_EFI_ERROR(StatusParameter) (VOID)(StatusParameter)
 #endif
 
 /**
@@ -372,6 +378,9 @@ DebugPrintLevelEnabled (  #if !defined(MDEPKG_NDEBUG)
   #define ASSERT_PROTOCOL_ALREADY_INSTALLED(Handle, Guid)                      
         \
     do {                                                                       
         \
+      (VOID)(Handle);                                                          
         \
+      (VOID)(Guid);                                                            
         \
+                                                                               
         
+ \
       if (DebugAssertEnabled ()) {                                             
         \
         VOID  *Instance;                                                       
         \
         ASSERT (Guid != NULL);                                                 
         \
@@ -387,7 +396,7 @@ DebugPrintLevelEnabled (
       }                                                                        
         \
     } while (FALSE)
 #else
-  #define ASSERT_PROTOCOL_ALREADY_INSTALLED(Handle, Guid)
+  #define ASSERT_PROTOCOL_ALREADY_INSTALLED(Handle, Guid) 
+ (VOID)(Handle)
 #endif
 
 /**
--
2.7.4.windows.1

_______________________________________________
edk2-devel mailing list
[email protected]
https://lists.01.org/mailman/listinfo/edk2-devel
_______________________________________________
edk2-devel mailing list
[email protected]
https://lists.01.org/mailman/listinfo/edk2-devel

Reply via email to