[llvm] r300174 - [Orc] Fix bool serialization for RawByteChannels.

Lang Hames via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 12 22:23:51 PDT 2017


Author: lhames
Date: Thu Apr 13 00:23:50 2017
New Revision: 300174

URL: http://llvm.org/viewvc/llvm-project?rev=300174&view=rev
Log:
[Orc] Fix bool serialization for RawByteChannels.

The bool type may be larger than the char type, so assuming we can cast from
bool to char and write a byte out to the stream is unsafe.

Hopefully this will get RPCUtilsTest.ReturnExpectedFailure passing on the bots.

Modified:
    llvm/trunk/include/llvm/ExecutionEngine/Orc/RawByteChannel.h

Modified: llvm/trunk/include/llvm/ExecutionEngine/Orc/RawByteChannel.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ExecutionEngine/Orc/RawByteChannel.h?rev=300174&r1=300173&r2=300174&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ExecutionEngine/Orc/RawByteChannel.h (original)
+++ llvm/trunk/include/llvm/ExecutionEngine/Orc/RawByteChannel.h Thu Apr 13 00:23:50 2017
@@ -121,11 +121,19 @@ class SerializationTraits<ChannelT, bool
                               RawByteChannel, ChannelT>::value>::type> {
 public:
   static Error serialize(ChannelT &C, bool V) {
-    return C.appendBytes(reinterpret_cast<const char *>(&V), 1);
+    uint8_t Tmp = V ? 1 : 0;
+    if (auto Err =
+          C.appendBytes(reinterpret_cast<const char *>(&Tmp), 1))
+      return Err;
+    return Error::success();
   }
 
   static Error deserialize(ChannelT &C, bool &V) {
-    return C.readBytes(reinterpret_cast<char *>(&V), 1);
+    uint8_t Tmp = 0;
+    if (auto Err = C.readBytes(reinterpret_cast<char *>(&Tmp), 1))
+      return Err;
+    V = Tmp != 0;
+    return Error::success();
   }
 };
 




More information about the llvm-commits mailing list