brucem created this revision.
brucem added a reviewer: clayborg.
brucem added a subscriber: lldb-commits.

This replaces (void)x; usages where they x was subsequently
involved in an assertion with this macro to make the
intent more clear.

http://reviews.llvm.org/D11451

Files:
  include/lldb/lldb-defines.h
  source/Host/posix/MainLoopPosix.cpp
  source/Interpreter/CommandInterpreter.cpp
  source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp
  
source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTypeEncodingParser.cpp
  source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp
  source/Symbol/ClangASTImporter.cpp
  source/Target/Process.cpp
  tools/debugserver/source/DNB.cpp
  tools/debugserver/source/DNBDefs.h
  tools/debugserver/source/MacOSX/MachProcess.mm
  tools/debugserver/source/MacOSX/arm/DNBArchImpl.cpp
  tools/debugserver/source/MacOSX/arm64/DNBArchImplARM64.cpp
  tools/debugserver/source/MacOSX/i386/DNBArchImplI386.cpp
  tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp

Index: tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp
===================================================================
--- tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp
+++ tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp
@@ -2089,7 +2089,7 @@
             
             // make sure we end up with exactly what we think we should have
             size_t bytes_written = p - (uint8_t *)buf;
-            (void)bytes_written;
+            UNUSED_IF_ASSERT_DISABLED(bytes_written);
             assert (bytes_written == size);
         }
 
@@ -2177,7 +2177,7 @@
         
         // make sure we end up with exactly what we think we should have
         size_t bytes_written = p - (uint8_t *)buf;
-        (void)bytes_written;
+        UNUSED_IF_ASSERT_DISABLED(bytes_written);
         assert (bytes_written == size);
 
         kern_return_t kret;
Index: tools/debugserver/source/MacOSX/i386/DNBArchImplI386.cpp
===================================================================
--- tools/debugserver/source/MacOSX/i386/DNBArchImplI386.cpp
+++ tools/debugserver/source/MacOSX/i386/DNBArchImplI386.cpp
@@ -1703,7 +1703,7 @@
             
             // make sure we end up with exactly what we think we should have
             size_t bytes_written = p - (uint8_t *)buf;
-            (void)bytes_written;
+            UNUSED_IF_ASSERT_DISABLED(bytes_written);
             assert (bytes_written == size);
         }
     }
@@ -1789,7 +1789,7 @@
         
         // make sure we end up with exactly what we think we should have
         size_t bytes_written = p - (uint8_t *)buf;
-        (void)bytes_written;
+        UNUSED_IF_ASSERT_DISABLED(bytes_written);
         assert (bytes_written == size);
         kern_return_t kret;
         if ((kret = SetGPRState()) != KERN_SUCCESS)
Index: tools/debugserver/source/MacOSX/arm64/DNBArchImplARM64.cpp
===================================================================
--- tools/debugserver/source/MacOSX/arm64/DNBArchImplARM64.cpp
+++ tools/debugserver/source/MacOSX/arm64/DNBArchImplARM64.cpp
@@ -1995,7 +1995,7 @@
         p += sizeof(m_state.context.exc);
         
         size_t bytes_written = p - (uint8_t *)buf;
-        (void)bytes_written;
+        UNUSED_IF_ASSERT_DISABLED(bytes_written);
         assert (bytes_written == size);
     }
     DNBLogThreadedIf (LOG_THREAD, "DNBArchMachARM64::GetRegisterContext (buf = %p, len = %zu) => %zu", buf, buf_len, size);
@@ -2028,7 +2028,7 @@
         p += sizeof(m_state.context.exc);
         
         size_t bytes_written = p - (uint8_t *)buf;
-        (void)bytes_written;
+        UNUSED_IF_ASSERT_DISABLED(bytes_written);
         assert (bytes_written == size);
         SetGPRState();
         SetVFPState();
Index: tools/debugserver/source/MacOSX/arm/DNBArchImpl.cpp
===================================================================
--- tools/debugserver/source/MacOSX/arm/DNBArchImpl.cpp
+++ tools/debugserver/source/MacOSX/arm/DNBArchImpl.cpp
@@ -2060,7 +2060,7 @@
         p += sizeof(m_state.context.exc);
 
         size_t bytes_written = p - (uint8_t *)buf;
-        (void)bytes_written;
+        UNUSED_IF_ASSERT_DISABLED(bytes_written);
         assert (bytes_written == size);
 
     }
@@ -2094,7 +2094,7 @@
         p += sizeof(m_state.context.exc);
         
         size_t bytes_written = p - (uint8_t *)buf;
-        (void)bytes_written;
+        UNUSED_IF_ASSERT_DISABLED(bytes_written);
         assert (bytes_written == size);
 
         if (SetGPRState() | SetVFPState() | SetEXCState())
Index: tools/debugserver/source/MacOSX/MachProcess.mm
===================================================================
--- tools/debugserver/source/MacOSX/MachProcess.mm
+++ tools/debugserver/source/MacOSX/MachProcess.mm
@@ -1032,7 +1032,7 @@
         DNBBreakpoint *bp = bps[i];
 
         const bool intersects = bp->IntersectsRange(addr, size, &intersect_addr, &intersect_size, &opcode_offset);
-        (void)intersects;
+        UNUSED_IF_ASSERT_DISABLED(intersects);
         assert(intersects);
         assert(addr <= intersect_addr && intersect_addr < addr + size);
         assert(addr < intersect_addr + intersect_size && intersect_addr + intersect_size <= addr + size);
Index: tools/debugserver/source/DNBDefs.h
===================================================================
--- tools/debugserver/source/DNBDefs.h
+++ tools/debugserver/source/DNBDefs.h
@@ -365,4 +365,6 @@
 typedef nub_size_t (*DNBCallbackCopyExecutableImageInfos)(nub_process_t pid, struct DNBExecutableImageInfo **image_infos, nub_bool_t only_changed, void *baton);
 typedef void (*DNBCallbackLog)(void *baton, uint32_t flags, const char *format, va_list args);
 
+#define UNUSED_IF_ASSERT_DISABLED(x) ((void)(x))
+
 #endif    // #ifndef __DNBDefs_h__
Index: tools/debugserver/source/DNB.cpp
===================================================================
--- tools/debugserver/source/DNB.cpp
+++ tools/debugserver/source/DNB.cpp
@@ -446,7 +446,7 @@
             else
             {
                 bool res = AddProcessToMap(pid, processSP);
-                (void)res;
+                UNUSED_IF_ASSERT_DISABLED(res);
                 assert(res && "Couldn't add process to map!");
                 return pid;
             }
@@ -495,7 +495,7 @@
         if (pid != INVALID_NUB_PROCESS)
         {
             bool res = AddProcessToMap(pid, processSP);
-            (void)res;
+            UNUSED_IF_ASSERT_DISABLED(res);
             assert(res && "Couldn't add process to map!");
             spawn_waitpid_thread(pid);
         }
Index: source/Target/Process.cpp
===================================================================
--- source/Target/Process.cpp
+++ source/Target/Process.cpp
@@ -2843,7 +2843,7 @@
                     size_t intersect_size;
                     size_t opcode_offset;
                     const bool intersects = bp->IntersectsRange(addr, size, &intersect_addr, &intersect_size, &opcode_offset);
-                    (void)intersects;
+                    UNUSED_IF_ASSERT_DISABLED(intersects);
                     assert(intersects);
                     assert(addr <= intersect_addr && intersect_addr < addr + size);
                     assert(addr < intersect_addr + intersect_size && intersect_addr + intersect_size <= addr + size);
Index: source/Symbol/ClangASTImporter.cpp
===================================================================
--- source/Symbol/ClangASTImporter.cpp
+++ source/Symbol/ClangASTImporter.cpp
@@ -623,7 +623,7 @@
         m_decls_to_deport->erase(decl);
         
         DeclOrigin &origin = to_context_md->m_origins[decl];
-        (void)origin;
+        UNUSED_IF_ASSERT_DISABLED(origin);
         
         assert (origin.ctx == m_source_ctx);    // otherwise we should never have added this
                                                 // because it doesn't need to be deported
Index: source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp
===================================================================
--- source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp
+++ source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp
@@ -133,7 +133,7 @@
     int platform_port;
     std::string platform_path;
     bool ok = UriParser::Parse(GetConnection()->GetURI().c_str(), platform_scheme, platform_ip, platform_port, platform_path);
-    (void)ok;
+    UNUSED_IF_ASSERT_DISABLED(ok);
     assert(ok);
     Error error = StartDebugserverProcess (
                                      platform_ip.c_str(),
Index: source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTypeEncodingParser.cpp
===================================================================
--- source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTypeEncodingParser.cpp
+++ source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTypeEncodingParser.cpp
@@ -44,7 +44,7 @@
     while (type.HasAtLeast(1) && type.Peek() != '"')
         buffer.Printf("%c",type.Next());
     StringLexer::Character next = type.Next();
-    (void) next; // Avoid warnings when assertions are off.
+    UNUSED_IF_ASSERT_DISABLED(next);
     assert (next == '"');
     return buffer.GetString();
 }
Index: source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp
===================================================================
--- source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp
+++ source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp
@@ -718,7 +718,7 @@
         const size_t count_v13 = count_v11 +
                                  addr_size +         // sharedCacheSlide
                                  sizeof (uuid_t);    // sharedCacheUUID
-        (void) count_v13; // Avoid warnings when assertions are off.
+        UNUSED_IF_ASSERT_DISABLED(count_v13);
         assert (sizeof (buf) >= count_v13);
 
         Error error;
Index: source/Interpreter/CommandInterpreter.cpp
===================================================================
--- source/Interpreter/CommandInterpreter.cpp
+++ source/Interpreter/CommandInterpreter.cpp
@@ -511,8 +511,7 @@
             char buffer[1024];
             int num_printed = snprintf(buffer, 1024, "%s %s", break_regexes[i][1], "-o");
             assert (num_printed < 1024);
-	    // Quiet unused variable warning for release builds.
-	    (void) num_printed;
+            UNUSED_IF_ASSERT_DISABLED(num_printed);
             success = tbreak_regex_cmd_ap->AddRegexCommand (break_regexes[i][0], buffer);
             if (!success)
                 break;
Index: source/Host/posix/MainLoopPosix.cpp
===================================================================
--- source/Host/posix/MainLoopPosix.cpp
+++ source/Host/posix/MainLoopPosix.cpp
@@ -97,7 +97,7 @@
 MainLoopPosix::UnregisterReadObject(IOObject::WaitableHandle handle)
 {
     bool erased = m_read_fds.erase(handle);
-    (void) erased;
+    UNUSED_IF_ASSERT_DISABLED(erased);
     assert(erased);
 }
 
Index: include/lldb/lldb-defines.h
===================================================================
--- include/lldb/lldb-defines.h
+++ include/lldb/lldb-defines.h
@@ -137,6 +137,8 @@
 #define __attribute__(X)
 #endif
 
+#define UNUSED_IF_ASSERT_DISABLED(x) ((void)(x))
+
 #if defined(__cplusplus)
 
 //----------------------------------------------------------------------
_______________________________________________
lldb-commits mailing list
lldb-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/lldb-commits

Reply via email to