Fix a use-after-scope from 99023627010bbfefb71e25a2b4d056de1cbd354e
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>
Fri, 29 Oct 2021 23:24:11 +0000 (16:24 -0700)
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>
Fri, 29 Oct 2021 23:25:13 +0000 (16:25 -0700)
clang/lib/Basic/FileManager.cpp

index 1cb52d5..f4cf278 100644 (file)
@@ -123,14 +123,14 @@ FileManager::getDirectoryRef(StringRef DirName, bool CacheFailure) {
       DirName != llvm::sys::path::root_path(DirName) &&
       llvm::sys::path::is_separator(DirName.back()))
     DirName = DirName.substr(0, DirName.size()-1);
+  Optional<std::string> DirNameStr;
   if (is_style_windows(llvm::sys::path::Style::native)) {
     // Fixing a problem with "clang C:test.c" on Windows.
     // Stat("C:") does not recognize "C:" as a valid directory
-    std::string DirNameStr;
     if (DirName.size() > 1 && DirName.back() == ':' &&
         DirName.equals_insensitive(llvm::sys::path::root_name(DirName))) {
       DirNameStr = DirName.str() + '.';
-      DirName = DirNameStr;
+      DirName = *DirNameStr;
     }
   }