[PATCH] D58643: [Support] Make raw_string_ostream unbuffered

Roman Lebedev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 25 13:23:04 PST 2019


lebedev.ri reopened this revision.
lebedev.ri added a comment.
This revision is now accepted and ready to land.

Uhm, but if we disable buffering, and cripple `flush()`, shouldn't we also make it impossible to turn the buffering back on?
Existing test fails with this change, and if i add similar test with `SmallString`/`raw_svector_ostream` it also fails in trunk.

  TEST(raw_ostreamTest, TinyBuffer) {
    std::string Str;
    raw_string_ostream OS(Str);
    OS.SetBufferSize(1);
    OS << "hello";
    OS << 1;
    OS << 'w' << 'o' << 'r' << 'l' << 'd';
    EXPECT_EQ("hello1world", OS.str());
  }
  
  TEST(raw_svector_ostreamTest, TinyBuffer) {
    llvm::SmallString<0> Str;
    raw_svector_ostream OS(Str);
    OS.SetBufferSize(1);
    OS << "hello";
    OS << 1;
    OS << 'w' << 'o' << 'r' << 'l' << 'd';
    EXPECT_EQ("hello1world", OS.str());
  }



  $ unittests/Support/SupportTests --gtest_filter=*TinyBuffer
  Note: Google Test filter = *TinyBuffer
  [==========] Running 2 tests from 2 test cases.
  [----------] Global test environment set-up.
  [----------] 1 test from raw_ostreamTest
  [ RUN      ] raw_ostreamTest.TinyBuffer
  /build/llvm/unittests/Support/raw_ostream_test.cpp:127: Failure
        Expected: "hello1world"
  To be equal to: OS.str()
        Which is: "hello1worl"
  [  FAILED  ] raw_ostreamTest.TinyBuffer (0 ms)
  [----------] 1 test from raw_ostreamTest (0 ms total)
  
  [----------] 1 test from raw_svector_ostreamTest
  [ RUN      ] raw_svector_ostreamTest.TinyBuffer
  /build/llvm/unittests/Support/raw_ostream_test.cpp:137: Failure
        Expected: "hello1world"
        Which is: 0x55cc2aeca73f
  To be equal to: OS.str()
        Which is: { 'h' (104, 0x68), 'e' (101, 0x65), 'l' (108, 0x6C), 'l' (108, 0x6C), 'o' (111, 0x6F), '1' (49, 0x31), 'w' (119, 0x77), 'o' (111, 0x6F), 'r' (114, 0x72), 'l' (108, 0x6C) }
  SupportTests: /build/llvm/lib/Support/raw_ostream.cpp:72: virtual llvm::raw_ostream::~raw_ostream(): Assertion `OutBufCur == OutBufStart && "raw_ostream destructor called with non-empty buffer!"' failed.
   #0 0x00007fb00164150a llvm::sys::PrintStackTrace(llvm::raw_ostream&) (/build/llvm-build-GCC-release/lib/libLLVMSupport.so.9svn+0x1b150a)
   #1 0x00007fb00163f2f4 llvm::sys::RunSignalHandlers() (/build/llvm-build-GCC-release/lib/libLLVMSupport.so.9svn+0x1af2f4)
   #2 0x00007fb00163f455 SignalHandler(int) (/build/llvm-build-GCC-release/lib/libLLVMSupport.so.9svn+0x1af455)
   #3 0x00007fb0014426e0 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x126e0)
   #4 0x00007fb000eff8bb gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x378bb)
   #5 0x00007fb000eea535 abort (/lib/x86_64-linux-gnu/libc.so.6+0x22535)
   #6 0x00007fb000eea40f (/lib/x86_64-linux-gnu/libc.so.6+0x2240f)
   #7 0x00007fb000ef80f2 (/lib/x86_64-linux-gnu/libc.so.6+0x300f2)
   #8 0x00007fb00161fd40 llvm::raw_svector_ostream::~raw_svector_ostream() (/build/llvm-build-GCC-release/lib/libLLVMSupport.so.9svn+0x18fd40)
   #9 0x000055cc2b1fc226 (anonymous namespace)::raw_svector_ostreamTest_TinyBuffer_Test::TestBody() (unittests/Support/SupportTests+0x37c226)
  #10 0x00007fb00140a98a testing::Test::Run() (/build/llvm-build-GCC-release/lib/libgtest.so.9svn+0x4298a)
  #11 0x00007fb00140aad0 testing::TestInfo::Run() (/build/llvm-build-GCC-release/lib/libgtest.so.9svn+0x42ad0)
  #12 0x00007fb00140ab95 testing::TestCase::Run() (/build/llvm-build-GCC-release/lib/libgtest.so.9svn+0x42b95)
  #13 0x00007fb00140b05c testing::internal::UnitTestImpl::RunAllTests() (/build/llvm-build-GCC-release/lib/libgtest.so.9svn+0x4305c)
  #14 0x00007fb00140b147 testing::UnitTest::Run() (/build/llvm-build-GCC-release/lib/libgtest.so.9svn+0x43147)
  #15 0x00007fb001429161 main (/build/llvm-build-GCC-release/lib/libgtest_main.so.9svn+0x1161)
  #16 0x00007fb000eec09b __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2409b)
  #17 0x000055cc2af6c02a _start (unittests/Support/SupportTests+0xec02a)
  Aborted


Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D58643/new/

https://reviews.llvm.org/D58643





More information about the llvm-commits mailing list