Revert "[clang][NFC] Clean up createDefaultOutputFile()"
authorTimm Bäder <tbaeder@redhat.com>
Tue, 20 Dec 2022 10:46:09 +0000 (11:46 +0100)
committerTimm Bäder <tbaeder@redhat.com>
Tue, 20 Dec 2022 10:46:09 +0000 (11:46 +0100)
This reverts commit d20101db48945e9d7a19ce3edcfd91d7e1aeadab.

Lifetime of the string is not what I thought it was it seems.

clang/lib/Frontend/CompilerInstance.cpp

index 858c580..a124566 100644 (file)
@@ -805,13 +805,14 @@ std::unique_ptr<raw_pwrite_stream> CompilerInstance::createDefaultOutputFile(
     bool Binary, StringRef InFile, StringRef Extension, bool RemoveFileOnSignal,
     bool CreateMissingDirectories, bool ForceUseTemporary) {
   StringRef OutputPath = getFrontendOpts().OutputFile;
+  std::optional<SmallString<128>> PathStorage;
   if (OutputPath.empty()) {
     if (InFile == "-" || Extension.empty()) {
       OutputPath = "-";
     } else {
-      SmallString<128> PathStorage = InFile;
-      llvm::sys::path::replace_extension(PathStorage, Extension);
-      OutputPath = PathStorage;
+      PathStorage.emplace(InFile);
+      llvm::sys::path::replace_extension(*PathStorage, Extension);
+      OutputPath = *PathStorage;
     }
   }