Просмотр исходного кода

Switched from raw_ostream to pwrite_stream in the driver.cpp (#2937)

Co-authored-by: Farzana Ahmed Siddique <fasiddique@google.com>
Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
Farzana Ahmed Siddique 2 лет назад
Родитель
Сommit
0b49ae32de

+ 2 - 2
explorer/file_test.cpp

@@ -34,8 +34,8 @@ class ParseAndExecuteTestFile : public FileTestBase {
   }
 
   auto RunWithFiles(const llvm::SmallVector<TestFile>& test_files,
-                    llvm::raw_ostream& stdout, llvm::raw_ostream& stderr)
-      -> bool override {
+                    llvm::raw_pwrite_stream& stdout,
+                    llvm::raw_pwrite_stream& stderr) -> bool override {
     if (test_files.size() != 1) {
       ADD_FAILURE() << "Only 1 file is supported: " << test_files.size()
                     << " provided";

+ 2 - 2
testing/file_test/file_test_base.h

@@ -73,8 +73,8 @@ class FileTestBase : public testing::Test {
   // implementation, which will validate stdout and stderr. The return value
   // should be false when "fail_" is in the filename.
   virtual auto RunWithFiles(const llvm::SmallVector<TestFile>& test_files,
-                            llvm::raw_ostream& stdout,
-                            llvm::raw_ostream& stderr) -> bool = 0;
+                            llvm::raw_pwrite_stream& stdout,
+                            llvm::raw_pwrite_stream& stderr) -> bool = 0;
 
   // Runs a test and compares output. This keeps output split by line so that
   // issues are a little easier to identify by the different line.

+ 2 - 2
testing/file_test/file_test_base_test.cpp

@@ -35,8 +35,8 @@ class FileTestBaseTest : public FileTestBase {
   }
 
   auto RunWithFiles(const llvm::SmallVector<TestFile>& test_files,
-                    llvm::raw_ostream& stdout, llvm::raw_ostream& stderr)
-      -> bool override {
+                    llvm::raw_pwrite_stream& stdout,
+                    llvm::raw_pwrite_stream& stderr) -> bool override {
     auto filename = path().filename();
     if (filename == "example.carbon") {
       EXPECT_THAT(test_files, ElementsAre(HasFilename("example.carbon")));

+ 1 - 0
testing/util/BUILD

@@ -30,6 +30,7 @@ cc_library(
     deps = [
         "//common:ostream",
         "@com_google_googletest//:gtest",
+        "@llvm-project//llvm:Support",
     ],
 )
 

+ 5 - 4
testing/util/test_raw_ostream.h

@@ -10,13 +10,14 @@
 #include <string>
 
 #include "common/ostream.h"
+#include "llvm/ADT/SmallString.h"
 
 namespace Carbon::Testing {
 
 // A raw_ostream that makes it easy to repeatedly check streamed output.
-class TestRawOstream : public llvm::raw_string_ostream {
+class TestRawOstream : public llvm::raw_svector_ostream {
  public:
-  explicit TestRawOstream() : llvm::raw_string_ostream(buffer_) {}
+  explicit TestRawOstream() : llvm::raw_svector_ostream(buffer_) {}
 
   ~TestRawOstream() override {
     if (!buffer_.empty()) {
@@ -27,13 +28,13 @@ class TestRawOstream : public llvm::raw_string_ostream {
   // Flushes the stream and returns the contents so far, clearing the stream
   // back to empty.
   auto TakeStr() -> std::string {
-    std::string result = std::move(buffer_);
+    std::string result = buffer_.str().str();
     buffer_.clear();
     return result;
   }
 
  private:
-  std::string buffer_;
+  llvm::SmallString<16> buffer_;
 };
 
 }  // namespace Carbon::Testing

+ 4 - 4
toolchain/driver/driver.h

@@ -25,8 +25,8 @@ class Driver {
  public:
   // Constructs a driver with any error or informational output directed to a
   // specified stream.
-  Driver(llvm::vfs::FileSystem& fs, llvm::raw_ostream& output_stream,
-         llvm::raw_ostream& error_stream)
+  Driver(llvm::vfs::FileSystem& fs, llvm::raw_pwrite_stream& output_stream,
+         llvm::raw_pwrite_stream& error_stream)
       : fs_(fs), output_stream_(output_stream), error_stream_(error_stream) {
     (void)fs_;
   }
@@ -66,8 +66,8 @@ class Driver {
                        llvm::ArrayRef<llvm::StringRef> args) -> void;
 
   llvm::vfs::FileSystem& fs_;
-  llvm::raw_ostream& output_stream_;
-  llvm::raw_ostream& error_stream_;
+  llvm::raw_pwrite_stream& output_stream_;
+  llvm::raw_pwrite_stream& error_stream_;
   llvm::raw_ostream* vlog_stream_ = nullptr;
 };
 

+ 3 - 2
toolchain/driver/driver_file_test_base.h

@@ -5,6 +5,7 @@
 #ifndef CARBON_TOOLCHAIN_DRIVER_DRIVER_FILE_TEST_BASE_H_
 #define CARBON_TOOLCHAIN_DRIVER_DRIVER_FILE_TEST_BASE_H_
 
+#include <cstdio>
 #include <fstream>
 
 #include "llvm/ADT/ScopeExit.h"
@@ -24,8 +25,8 @@ class DriverFileTestBase : public FileTestBase {
   using FileTestBase::FileTestBase;
 
   auto RunWithFiles(const llvm::SmallVector<TestFile>& test_files,
-                    llvm::raw_ostream& stdout, llvm::raw_ostream& stderr)
-      -> bool override {
+                    llvm::raw_pwrite_stream& stdout,
+                    llvm::raw_pwrite_stream& stderr) -> bool override {
     // Prepare a list of filenames for MakeArgs. Also create the files
     // in-memory.
     llvm::SmallVector<llvm::StringRef> test_file_names;

+ 2 - 1
toolchain/driver/driver_fuzzer.cpp

@@ -69,7 +69,8 @@ extern "C" auto LLVMFuzzerTestOneInput(const unsigned char* data, size_t size)
 
   llvm::vfs::InMemoryFileSystem fs;
   TestRawOstream error_stream;
-  Driver d(fs, llvm::nulls(), error_stream);
+  llvm::raw_null_ostream dest;
+  Driver d(fs, dest, error_stream);
   if (!d.RunFullCommand(args)) {
     if (error_stream.TakeStr().find("ERROR:") == std::string::npos) {
       llvm::errs() << "No error message on a failure!\n";