<p dir="ltr">Naively this sound unit testable, perhaps?</p>
<div class="gmail_quote">On Nov 20, 2014 9:20 PM, "Rafael Espindola" <<a href="mailto:rafael.espindola@gmail.com">rafael.espindola@gmail.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: rafael<br>
Date: Thu Nov 20 23:15:41 2014<br>
New Revision: 222505<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=222505&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=222505&view=rev</a><br>
Log:<br>
Fix a silly bug in StreamingMemoryObject.cpp.<br>
<br>
The logic for detecting EOF was wrong and would fail if we ever requested<br>
more than 16k past the last read position.<br>
<br>
Added:<br>
    llvm/trunk/unittests/Support/StreamingMemoryObject.cpp<br>
Modified:<br>
    llvm/trunk/include/llvm/Support/StreamingMemoryObject.h<br>
    llvm/trunk/unittests/Support/CMakeLists.txt<br>
<br>
Modified: llvm/trunk/include/llvm/Support/StreamingMemoryObject.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/StreamingMemoryObject.h?rev=222505&r1=222504&r2=222505&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/StreamingMemoryObject.h?rev=222505&r1=222504&r2=222505&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/Support/StreamingMemoryObject.h (original)<br>
+++ llvm/trunk/include/llvm/Support/StreamingMemoryObject.h Thu Nov 20 23:15:41 2014<br>
@@ -65,19 +65,20 @@ private:<br>
   // Most of the requests will be small, but we fetch at kChunkSize bytes<br>
   // at a time to avoid making too many potentially expensive GetBytes calls<br>
   bool fetchToPos(size_t Pos) const {<br>
-    if (EOFReached) return Pos < ObjectSize;<br>
+    if (EOFReached)<br>
+      return Pos < ObjectSize;<br>
     while (Pos >= BytesRead) {<br>
       Bytes.resize(BytesRead + BytesSkipped + kChunkSize);<br>
       size_t bytes = Streamer->GetBytes(&Bytes[BytesRead + BytesSkipped],<br>
                                         kChunkSize);<br>
       BytesRead += bytes;<br>
-      if (BytesRead <= Pos) { // reached EOF/ran out of bytes<br>
+      if (bytes != kChunkSize) { // reached EOF/ran out of bytes<br>
         ObjectSize = BytesRead;<br>
         EOFReached = true;<br>
-        return false;<br>
+        break;<br>
       }<br>
     }<br>
-    return true;<br>
+    return Pos < BytesRead;<br>
   }<br>
<br>
   StreamingMemoryObject(const StreamingMemoryObject&) LLVM_DELETED_FUNCTION;<br>
<br>
Modified: llvm/trunk/unittests/Support/CMakeLists.txt<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Support/CMakeLists.txt?rev=222505&r1=222504&r2=222505&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Support/CMakeLists.txt?rev=222505&r1=222504&r2=222505&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/unittests/Support/CMakeLists.txt (original)<br>
+++ llvm/trunk/unittests/Support/CMakeLists.txt Thu Nov 20 23:15:41 2014<br>
@@ -32,6 +32,7 @@ add_llvm_unittest(SupportTests<br>
   ScaledNumberTest.cpp<br>
   SourceMgrTest.cpp<br>
   SpecialCaseListTest.cpp<br>
+  StreamingMemoryObject.cpp<br>
   StringPool.cpp<br>
   SwapByteOrderTest.cpp<br>
   ThreadLocalTest.cpp<br>
<br>
Added: llvm/trunk/unittests/Support/StreamingMemoryObject.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Support/StreamingMemoryObject.cpp?rev=222505&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Support/StreamingMemoryObject.cpp?rev=222505&view=auto</a><br>
==============================================================================<br>
--- llvm/trunk/unittests/Support/StreamingMemoryObject.cpp (added)<br>
+++ llvm/trunk/unittests/Support/StreamingMemoryObject.cpp Thu Nov 20 23:15:41 2014<br>
@@ -0,0 +1,30 @@<br>
+//===- llvm/unittest/Support/StreamingMemoryObject.cpp - unit tests -------===//<br>
+//<br>
+//                     The LLVM Compiler Infrastructure<br>
+//<br>
+// This file is distributed under the University of Illinois Open Source<br>
+// License. See LICENSE.TXT for details.<br>
+//<br>
+//===----------------------------------------------------------------------===//<br>
+<br>
+#include "llvm/Support/StreamingMemoryObject.h"<br>
+#include "gtest/gtest.h"<br>
+<br>
+#include <string.h><br>
+<br>
+using namespace llvm;<br>
+<br>
+namespace {<br>
+class NullDataStreamer : public DataStreamer {<br>
+  size_t GetBytes(unsigned char *buf, size_t len) override {<br>
+    memset(buf, 0, len);<br>
+    return len;<br>
+  }<br>
+};<br>
+}<br>
+<br>
+TEST(StreamingMemoryObject, Test) {<br>
+  auto *DS = new NullDataStreamer();<br>
+  StreamingMemoryObject O(DS);<br>
+  EXPECT_TRUE(O.isValidAddress(32 * 1024));<br>
+}<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</blockquote></div>