Add UNUSED_IF_ASSERT_DISABLED and apply it.

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
This commit is contained in:
Bruce Mitchener 2015-07-24 00:23:29 +00:00
parent ff8fbf9f90
commit 8a67bf7298
15 changed files with 22 additions and 19 deletions

View File

@ -137,6 +137,8 @@
#define __attribute__(X)
#endif
#define UNUSED_IF_ASSERT_DISABLED(x) ((void)(x))
#if defined(__cplusplus)
//----------------------------------------------------------------------

View 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);
}

View 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;

View 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;

View 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();
}

View 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(),

View 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

View 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);

View 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);
}

View 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__

View 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);

View 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())

View 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();

View 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)

View 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;