[llvm-commits] [llvm] r163948 - in /llvm/trunk: include/llvm/Support/FormattedStream.h unittests/Support/CMakeLists.txt unittests/Support/formatted_raw_ostream_test.cpp
Daniel Dunbar
daniel at zuster.org
Fri Sep 14 16:15:56 PDT 2012
Author: ddunbar
Date: Fri Sep 14 18:15:56 2012
New Revision: 163948
URL: http://llvm.org/viewvc/llvm-project?rev=163948&view=rev
Log:
formatted_raw_ostream: Fix a serious bug in tell().
- The current_pos function is supposed to return all the written bytes, not the
current position of the underlying stream.
- This caused tell() to be broken whenever the underlying stream had buffered
content.
Added:
llvm/trunk/unittests/Support/formatted_raw_ostream_test.cpp
Modified:
llvm/trunk/include/llvm/Support/FormattedStream.h
llvm/trunk/unittests/Support/CMakeLists.txt
Modified: llvm/trunk/include/llvm/Support/FormattedStream.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/FormattedStream.h?rev=163948&r1=163947&r2=163948&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/FormattedStream.h (original)
+++ llvm/trunk/include/llvm/Support/FormattedStream.h Fri Sep 14 18:15:56 2012
@@ -60,9 +60,10 @@
/// current_pos - Return the current position within the stream,
/// not counting the bytes currently in the buffer.
virtual uint64_t current_pos() const {
- // This has the same effect as calling TheStream.current_pos(),
- // but that interface is private.
- return TheStream->tell() - TheStream->GetNumBytesInBuffer();
+ // Our current position in the stream is all the contents which have been
+ // written to the underlying stream (*not* the current position of the
+ // underlying stream).
+ return TheStream->tell();
}
/// ComputeColumn - Examine the given output buffer and figure out which
Modified: llvm/trunk/unittests/Support/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Support/CMakeLists.txt?rev=163948&r1=163947&r2=163948&view=diff
==============================================================================
--- llvm/trunk/unittests/Support/CMakeLists.txt (original)
+++ llvm/trunk/unittests/Support/CMakeLists.txt Fri Sep 14 18:15:56 2012
@@ -18,10 +18,11 @@
ManagedStatic.cpp
MathExtrasTest.cpp
Path.cpp
- raw_ostream_test.cpp
RegexTest.cpp
SwapByteOrderTest.cpp
TimeValue.cpp
ValueHandleTest.cpp
YAMLParserTest.cpp
+ formatted_raw_ostream.cpp
+ raw_ostream_test.cpp
)
Added: llvm/trunk/unittests/Support/formatted_raw_ostream_test.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Support/formatted_raw_ostream_test.cpp?rev=163948&view=auto
==============================================================================
--- llvm/trunk/unittests/Support/formatted_raw_ostream_test.cpp (added)
+++ llvm/trunk/unittests/Support/formatted_raw_ostream_test.cpp Fri Sep 14 18:15:56 2012
@@ -0,0 +1,33 @@
+//===- llvm/unittest/Support/formatted_raw_ostream_test.cpp ---------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "gtest/gtest.h"
+#include "llvm/ADT/SmallString.h"
+#include "llvm/Support/raw_ostream.h"
+#include "llvm/Support/FormattedStream.h"
+
+using namespace llvm;
+
+namespace {
+
+TEST(formatted_raw_ostreamTest, Test_Tell) {
+ // Check offset when underlying stream has buffer contents.
+ SmallString<128> A;
+ raw_svector_ostream B(A);
+ formatted_raw_ostream C(B);
+ char tmp[100] = "";
+
+ for (unsigned i = 0; i != 3; ++i) {
+ C.write(tmp, 100);
+
+ EXPECT_EQ(100*(i+1), (unsigned) C.tell());
+ }
+}
+
+}
More information about the llvm-commits
mailing list