<p dir="ltr"><br>
On Nov 20, 2014 9:36 PM, "Rafael Espíndola" <<a href="mailto:rafael.espindola@gmail.com">rafael.espindola@gmail.com</a>> wrote:<br>
><br>
> On 21 November 2014 00:30, David Blaikie <<a href="mailto:dblaikie@gmail.com">dblaikie@gmail.com</a>> wrote:<br>
> > Naively this sound unit testable, perhaps?<br>
><br>
> The patch has one, so yes :-)</p>
<p dir="ltr">Heh, don't mind me...</p>
<p dir="ltr">><br>
> > On Nov 20, 2014 9:20 PM, "Rafael Espindola" <<a href="mailto:rafael.espindola@gmail.com">rafael.espindola@gmail.com</a>><br>
> > wrote:<br>
> >><br>
> >> 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">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:<br>
> >> <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/StreamingMemoryObject.h?rev=222505&r1=222504&r2=222505&view=diff">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/StreamingMemoryObject.h?rev=222505&r1=222504&r2=222505&view=diff</a><br>
> >><br>
> >> ==============================================================================<br>
> >> --- llvm/trunk/include/llvm/Support/StreamingMemoryObject.h (original)<br>
> >> +++ llvm/trunk/include/llvm/Support/StreamingMemoryObject.h Thu Nov 20<br>
> >> 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<br>
> >> 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&)<br>
> >> LLVM_DELETED_FUNCTION;<br>
> >><br>
> >> Modified: llvm/trunk/unittests/Support/CMakeLists.txt<br>
> >> URL:<br>
> >> <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Support/CMakeLists.txt?rev=222505&r1=222504&r2=222505&view=diff">http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Support/CMakeLists.txt?rev=222505&r1=222504&r2=222505&view=diff</a><br>
> >><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:<br>
> >> <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Support/StreamingMemoryObject.cpp?rev=222505&view=auto">http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Support/StreamingMemoryObject.cpp?rev=222505&view=auto</a><br>
> >><br>
> >> ==============================================================================<br>
> >> --- llvm/trunk/unittests/Support/StreamingMemoryObject.cpp (added)<br>
> >> +++ llvm/trunk/unittests/Support/StreamingMemoryObject.cpp Thu Nov 20<br>
> >> 23:15:41 2014<br>
> >> @@ -0,0 +1,30 @@<br>
> >> +//===- llvm/unittest/Support/StreamingMemoryObject.cpp - unit tests<br>
> >> -------===//<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>
> >> +<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">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</p>