[llvm] r224114 - Silence gcc 4.9.1 warning 'xyz' is used uninitialized in this function.
Yaron Keren
yaron.keren at gmail.com
Fri Dec 12 11:15:36 PST 2014
I have propagated the error codes into ChildTarget.cpp.
What do you think of the attached patch?
2014-12-12 19:56 GMT+02:00 David Blaikie <dblaikie at gmail.com>:
>
>
>
> On Fri, Dec 12, 2014 at 3:07 AM, Yaron Keren <yaron.keren at gmail.com>
> wrote:
>
>> Author: yrnkrn
>> Date: Fri Dec 12 05:07:51 2014
>> New Revision: 224114
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=224114&view=rev
>> Log:
>> Silence gcc 4.9.1 warning 'xyz' is used uninitialized in this function.
>>
>> In release builds this is actually possible as without asserts there is
>> no testing of the actual read bytes and the variables could be partially
>> uninitialized.
>>
>
> Should we instead be actually testing the number of bytes read in a
> non-asserts build?
>
>
>>
>>
>> Modified:
>> llvm/trunk/tools/lli/ChildTarget/ChildTarget.cpp
>>
>> Modified: llvm/trunk/tools/lli/ChildTarget/ChildTarget.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/lli/ChildTarget/ChildTarget.cpp?rev=224114&r1=224113&r2=224114&view=diff
>>
>> ==============================================================================
>> --- llvm/trunk/tools/lli/ChildTarget/ChildTarget.cpp (original)
>> +++ llvm/trunk/tools/lli/ChildTarget/ChildTarget.cpp Fri Dec 12 05:07:51
>> 2014
>> @@ -97,15 +97,15 @@ void LLIChildTarget::handleMessage(LLIMe
>> // Incoming message handlers
>> void LLIChildTarget::handleAllocateSpace() {
>> // Read and verify the message data size.
>> - uint32_t DataSize;
>> + uint32_t DataSize = 0;
>> int rc = ReadBytes(&DataSize, 4);
>> (void)rc;
>> assert(rc == 4);
>> assert(DataSize == 8);
>>
>> // Read the message arguments.
>> - uint32_t Alignment;
>> - uint32_t AllocSize;
>> + uint32_t Alignment = 0;
>> + uint32_t AllocSize = 0;
>> rc = ReadBytes(&Alignment, 4);
>> assert(rc == 4);
>> rc = ReadBytes(&AllocSize, 4);
>> @@ -121,13 +121,13 @@ void LLIChildTarget::handleAllocateSpace
>>
>> void LLIChildTarget::handleLoadSection(bool IsCode) {
>> // Read the message data size.
>> - uint32_t DataSize;
>> + uint32_t DataSize = 0;
>> int rc = ReadBytes(&DataSize, 4);
>> (void)rc;
>> assert(rc == 4);
>>
>> // Read the target load address.
>> - uint64_t Addr;
>> + uint64_t Addr = 0;
>> rc = ReadBytes(&Addr, 8);
>> assert(rc == 8);
>> size_t BufferSize = DataSize - 8;
>> @@ -150,14 +150,14 @@ void LLIChildTarget::handleLoadSection(b
>>
>> void LLIChildTarget::handleExecute() {
>> // Read the message data size.
>> - uint32_t DataSize;
>> + uint32_t DataSize = 0;
>> int rc = ReadBytes(&DataSize, 4);
>> (void)rc;
>> assert(rc == 4);
>> assert(DataSize == 8);
>>
>> // Read the target address.
>> - uint64_t Addr;
>> + uint64_t Addr = 0;
>> rc = ReadBytes(&Addr, 8);
>> assert(rc == 8);
>>
>>
>>
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20141212/35b03173/attachment.html>
-------------- next part --------------
Index: tools/lli/ChildTarget/ChildTarget.cpp
===================================================================
--- tools/lli/ChildTarget/ChildTarget.cpp (revision 224141)
+++ tools/lli/ChildTarget/ChildTarget.cpp (working copy)
@@ -15,30 +15,29 @@
public:
void initialize();
LLIMessageType waitForIncomingMessage();
- void handleMessage(LLIMessageType messageType);
+ bool handleMessage(LLIMessageType messageType);
RemoteTarget *RT;
RPCChannel RPC;
private:
+ // Return true on success.
// Incoming message handlers
- void handleAllocateSpace();
- void handleLoadSection(bool IsCode);
- void handleExecute();
+ bool handleAllocateSpace();
+ bool handleLoadSection(bool IsCode);
+ bool handleExecute();
// Outgoing message handlers
- void sendChildActive();
- void sendAllocationResult(uint64_t Addr);
- void sendLoadStatus(uint32_t Status);
- void sendExecutionComplete(int Result);
+ bool sendChildActive();
+ bool sendAllocationResult(uint64_t Addr);
+ bool sendLoadStatus(uint32_t Status);
+ bool sendExecutionComplete(int Result);
// OS-specific functions
void initializeConnection();
- int WriteBytes(const void *Data, size_t Size) {
- return RPC.WriteBytes(Data, Size) ? Size : -1;
+ bool WriteBytes(const void *Data, size_t Size) {
+ return RPC.WriteBytes(Data, Size);
}
- int ReadBytes(void *Data, size_t Size) {
- return RPC.ReadBytes(Data, Size) ? Size : -1;
- }
+ bool ReadBytes(void *Data, size_t Size) { return RPC.ReadBytes(Data, Size); }
// Communication handles (OS-specific)
void *ConnectionData;
@@ -45,15 +44,15 @@
};
int main() {
- LLIChildTarget ThisChild;
+ LLIChildTarget ThisChild;
ThisChild.RT = new RemoteTarget();
ThisChild.initialize();
LLIMessageType MsgType;
do {
MsgType = ThisChild.waitForIncomingMessage();
- ThisChild.handleMessage(MsgType);
- } while (MsgType != LLI_Terminate &&
- MsgType != LLI_Error);
+ if (MsgType == LLI_Error)
+ break;
+ } while (ThisChild.handleMessage(MsgType));
delete ThisChild.RT;
return 0;
}
@@ -66,70 +65,67 @@
LLIMessageType LLIChildTarget::waitForIncomingMessage() {
int32_t MsgType = -1;
- if (ReadBytes(&MsgType, 4) > 0)
+ if (ReadBytes(&MsgType, 4))
return (LLIMessageType)MsgType;
return LLI_Error;
}
-void LLIChildTarget::handleMessage(LLIMessageType messageType) {
+bool LLIChildTarget::handleMessage(LLIMessageType messageType) {
switch (messageType) {
- case LLI_AllocateSpace:
- handleAllocateSpace();
- break;
- case LLI_LoadCodeSection:
- handleLoadSection(true);
- break;
- case LLI_LoadDataSection:
- handleLoadSection(false);
- break;
- case LLI_Execute:
- handleExecute();
- break;
- case LLI_Terminate:
- RT->stop();
- break;
- default:
- // FIXME: Handle error!
- break;
+ case LLI_AllocateSpace:
+ return handleAllocateSpace();
+ case LLI_LoadCodeSection:
+ return handleLoadSection(true);
+ break;
+ case LLI_LoadDataSection:
+ return handleLoadSection(false);
+ case LLI_Execute:
+ return handleExecute();
+ case LLI_Terminate:
+ RT->stop();
+ return false;
+ default:
+ // Error on unknown message.
+ return false;
}
}
// Incoming message handlers
-void LLIChildTarget::handleAllocateSpace() {
+bool LLIChildTarget::handleAllocateSpace() {
// Read and verify the message data size.
uint32_t DataSize = 0;
- int rc = ReadBytes(&DataSize, 4);
- (void)rc;
- assert(rc == 4);
- assert(DataSize == 8);
+ if (!ReadBytes(&DataSize, 4))
+ return false;
+ if (DataSize != 8)
+ return false;
// Read the message arguments.
uint32_t Alignment = 0;
uint32_t AllocSize = 0;
- rc = ReadBytes(&Alignment, 4);
- assert(rc == 4);
- rc = ReadBytes(&AllocSize, 4);
- assert(rc == 4);
+ if (!ReadBytes(&Alignment, 4))
+ return false;
+ if (!ReadBytes(&AllocSize, 4))
+ return false;
// Allocate the memory.
uint64_t Addr;
- RT->allocateSpace(AllocSize, Alignment, Addr);
+ if (!RT->allocateSpace(AllocSize, Alignment, Addr))
+ return false;
// Send AllocationResult message.
- sendAllocationResult(Addr);
+ return sendAllocationResult(Addr);
}
-void LLIChildTarget::handleLoadSection(bool IsCode) {
+bool LLIChildTarget::handleLoadSection(bool IsCode) {
// Read the message data size.
uint32_t DataSize = 0;
- int rc = ReadBytes(&DataSize, 4);
- (void)rc;
- assert(rc == 4);
+ if (!ReadBytes(&DataSize, 4))
+ return false;
// Read the target load address.
uint64_t Addr = 0;
- rc = ReadBytes(&Addr, 8);
- assert(rc == 8);
+ if (!ReadBytes(&Addr, 8))
+ return false;
size_t BufferSize = DataSize - 8;
if (!RT->isAllocatedMemory(Addr, BufferSize))
@@ -136,8 +132,7 @@
return sendLoadStatus(LLI_Status_NotAllocated);
// Read section data into previously allocated buffer
- rc = ReadBytes((void*)Addr, BufferSize);
- if (rc != (int)(BufferSize))
+ if (!ReadBytes((void *)Addr, BufferSize))
return sendLoadStatus(LLI_Status_IncompleteMsg);
// If IsCode, mark memory executable
@@ -145,94 +140,97 @@
sys::Memory::InvalidateInstructionCache((void *)Addr, BufferSize);
// Send MarkLoadComplete message.
- sendLoadStatus(LLI_Status_Success);
+ return sendLoadStatus(LLI_Status_Success);
}
-void LLIChildTarget::handleExecute() {
+bool LLIChildTarget::handleExecute() {
// Read the message data size.
uint32_t DataSize = 0;
int rc = ReadBytes(&DataSize, 4);
- (void)rc;
- assert(rc == 4);
- assert(DataSize == 8);
+ if (!ReadBytes(&DataSize, 4))
+ return false;
// Read the target address.
uint64_t Addr = 0;
- rc = ReadBytes(&Addr, 8);
- assert(rc == 8);
+ if (!ReadBytes(&Addr, 8))
+ return false;
// Call function
int32_t Result = -1;
- RT->executeCode(Addr, Result);
+ if (!RT->executeCode(Addr, Result))
+ return false;
// Send ExecutionResult message.
- sendExecutionComplete(Result);
+ return sendExecutionComplete(Result);
}
// Outgoing message handlers
-void LLIChildTarget::sendChildActive() {
+bool LLIChildTarget::sendChildActive() {
// Write the message type.
uint32_t MsgType = (uint32_t)LLI_ChildActive;
- int rc = WriteBytes(&MsgType, 4);
- (void)rc;
- assert(rc == 4);
+ if (!WriteBytes(&MsgType, 4))
+ return false;
// Write the data size.
uint32_t DataSize = 0;
- rc = WriteBytes(&DataSize, 4);
- assert(rc == 4);
+ if (!WriteBytes(&DataSize, 4))
+ return false;
+
+ return true;
}
-void LLIChildTarget::sendAllocationResult(uint64_t Addr) {
+bool LLIChildTarget::sendAllocationResult(uint64_t Addr) {
// Write the message type.
uint32_t MsgType = (uint32_t)LLI_AllocationResult;
- int rc = WriteBytes(&MsgType, 4);
- (void)rc;
- assert(rc == 4);
+ if (!WriteBytes(&MsgType, 4))
+ return false;
// Write the data size.
uint32_t DataSize = 8;
- rc = WriteBytes(&DataSize, 4);
- assert(rc == 4);
+ if (!WriteBytes(&DataSize, 4))
+ return false;
// Write the allocated address.
- rc = WriteBytes(&Addr, 8);
- assert(rc == 8);
+ if (!WriteBytes(&Addr, 8))
+ return false;
+
+ return true;
}
-void LLIChildTarget::sendLoadStatus(uint32_t Status) {
+bool LLIChildTarget::sendLoadStatus(uint32_t Status) {
// Write the message type.
uint32_t MsgType = (uint32_t)LLI_LoadResult;
- int rc = WriteBytes(&MsgType, 4);
- (void)rc;
- assert(rc == 4);
+ if (!WriteBytes(&MsgType, 4))
+ return false;
// Write the data size.
uint32_t DataSize = 4;
- rc = WriteBytes(&DataSize, 4);
- assert(rc == 4);
+ if (!WriteBytes(&DataSize, 4))
+ return false;
// Write the result.
- rc = WriteBytes(&Status, 4);
- assert(rc == 4);
+ if (!WriteBytes(&Status, 4))
+ return false;
+
+ return true;
}
-void LLIChildTarget::sendExecutionComplete(int Result) {
+bool LLIChildTarget::sendExecutionComplete(int Result) {
// Write the message type.
uint32_t MsgType = (uint32_t)LLI_ExecutionResult;
- int rc = WriteBytes(&MsgType, 4);
- (void)rc;
- assert(rc == 4);
+ if (!WriteBytes(&MsgType, 4))
+ return false;
-
// Write the data size.
uint32_t DataSize = 4;
- rc = WriteBytes(&DataSize, 4);
- assert(rc == 4);
+ if (!WriteBytes(&DataSize, 4))
+ return false;
// Write the result.
- rc = WriteBytes(&Result, 4);
- assert(rc == 4);
+ if (!WriteBytes(&Result, 4))
+ return false;
+
+ return true;
}
#ifdef LLVM_ON_UNIX
More information about the llvm-commits
mailing list