Add UNUSED_IF_ASSERT_DISABLED and apply it.
authorBruce Mitchener <bruce.mitchener@gmail.com>
Fri, 24 Jul 2015 00:23:29 +0000 (00:23 +0000)
committerBruce Mitchener <bruce.mitchener@gmail.com>
Fri, 24 Jul 2015 00:23:29 +0000 (00:23 +0000)
Summary:
This replaces (void)x; usages where they x was subsequently
involved in an assertion with this macro to make the
intent more clear.

Reviewers: clayborg

Subscribers: lldb-commits

Differential Revision: http://reviews.llvm.org/D11451

llvm-svn: 243074

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

index 9dce69a..175cecd 100644 (file)
 #define __attribute__(X)
 #endif
 
+#define UNUSED_IF_ASSERT_DISABLED(x) ((void)(x))
+
 #if defined(__cplusplus)
 
 //----------------------------------------------------------------------
index dccd7fa..897f2d1 100644 (file)
@@ -97,7 +97,7 @@ void
 MainLoopPosix::UnregisterReadObject(IOObject::WaitableHandle handle)
 {
     bool erased = m_read_fds.erase(handle);
-    (void) erased;
+    UNUSED_IF_ASSERT_DISABLED(erased);
     assert(erased);
 }
 
index 1da541b..965ba5b 100644 (file)
@@ -511,8 +511,7 @@ CommandInterpreter::LoadCommandDictionary ()
             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 433137c..7a82d18 100644 (file)
@@ -718,7 +718,7 @@ DynamicLoaderMacOSXDYLD::ReadAllImageInfosStructure ()
         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 dfb6094..10f7f82 100644 (file)
@@ -44,7 +44,7 @@ AppleObjCTypeEncodingParser::ReadQuotedString(lldb_utility::StringLexer& type)
     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 207fa52..bc1acee 100644 (file)
@@ -133,7 +133,7 @@ GDBRemoteCommunicationServerPlatform::Handle_qLaunchGDBServer (StringExtractorGD
     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 64542d1..038f26c 100644 (file)
@@ -623,7 +623,7 @@ ClangASTImporter::Minion::ExecuteDeportWorkQueues ()
         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 61248c6..17318e7 100644 (file)
@@ -2843,7 +2843,7 @@ Process::WriteMemory (addr_t addr, const void *buf, size_t size, Error &error)
                     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 f630d0b..5462cc4 100644 (file)
@@ -446,7 +446,7 @@ DNBProcessLaunch (const char *path,
             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 @@ DNBProcessAttach (nub_process_t attach_pid, struct timespec *timeout, char *err_
         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 15c33d5..b42329e 100644 (file)
@@ -365,4 +365,6 @@ typedef nub_addr_t (*DNBCallbackNameToAddress)(nub_process_t pid, const char *na
 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 44c2c81..b635b8a 100644 (file)
@@ -1032,7 +1032,7 @@ MachProcess::WriteMemory (nub_addr_t addr, nub_size_t size, const void *buf)
         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 0225873..b19a5b9 100644 (file)
@@ -2060,7 +2060,7 @@ DNBArchMachARM::GetRegisterContext (void *buf, nub_size_t buf_len)
         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 @@ DNBArchMachARM::SetRegisterContext (const void *buf, nub_size_t buf_len)
         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 ab81a6d..5d2b14d 100644 (file)
@@ -1995,7 +1995,7 @@ DNBArchMachARM64::GetRegisterContext (void *buf, nub_size_t buf_len)
         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 @@ DNBArchMachARM64::SetRegisterContext (const void *buf, nub_size_t buf_len)
         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 f3b29da..0046343 100644 (file)
@@ -1703,7 +1703,7 @@ DNBArchImplI386::GetRegisterContext (void *buf, nub_size_t buf_len)
             
             // 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 @@ DNBArchImplI386::SetRegisterContext (const void *buf, nub_size_t buf_len)
         
         // 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 76c9160..2867cd0 100644 (file)
@@ -2089,7 +2089,7 @@ DNBArchImplX86_64::GetRegisterContext (void *buf, nub_size_t buf_len)
             
             // 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 @@ DNBArchImplX86_64::SetRegisterContext (const void *buf, nub_size_t buf_len)
         
         // 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;