]> granicus.if.org Git - clang/commitdiff
[clang][HeaderSearch] Make sure there are no backslashes in suggestedPath
authorKadir Cetinkaya <kadircet@google.com>
Wed, 24 Apr 2019 08:45:03 +0000 (08:45 +0000)
committerKadir Cetinkaya <kadircet@google.com>
Wed, 24 Apr 2019 08:45:03 +0000 (08:45 +0000)
Reviewers: sammccall

Differential Revision: https://reviews.llvm.org/D60995

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@359075 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Lex/HeaderSearch.h
lib/Lex/HeaderSearch.cpp
unittests/Lex/HeaderSearchTest.cpp

index 879d24d0c65382bbdf4c905a97e53aa80cdc6677..7488d9e0e3d7887e1e16721e9bc14d7a86c496a0 100644 (file)
@@ -706,16 +706,18 @@ public:
   /// Retrieve a uniqued framework name.
   StringRef getUniqueFrameworkName(StringRef Framework);
 
-  /// Suggest a path by which the specified file could be found, for
-  /// use in diagnostics to suggest a #include.
+  /// Suggest a path by which the specified file could be found, for use in
+  /// diagnostics to suggest a #include. Returned path will only contain forward
+  /// slashes as separators.
   ///
   /// \param IsSystem If non-null, filled in to indicate whether the suggested
   ///        path is relative to a system header directory.
   std::string suggestPathToFileForDiagnostics(const FileEntry *File,
                                               bool *IsSystem = nullptr);
 
-  /// Suggest a path by which the specified file could be found, for
-  /// use in diagnostics to suggest a #include.
+  /// Suggest a path by which the specified file could be found, for use in
+  /// diagnostics to suggest a #include. Returned path will only contain forward
+  /// slashes as separators.
   ///
   /// \param WorkingDir If non-empty, this will be prepended to search directory
   /// paths that are relative.
index e0ffb8758cfb1d337aa5e02d049094c9e0b8452c..a26df9a7f607cf02083d5b4f52522f0aec032695 100644 (file)
@@ -1720,5 +1720,5 @@ std::string HeaderSearch::suggestPathToFileForDiagnostics(
 
   if (IsSystem)
     *IsSystem = BestPrefixLength ? BestSearchDir >= SystemDirIdx : false;
-  return File.drop_front(BestPrefixLength);
+  return path::convert_to_slash(File.drop_front(BestPrefixLength));
 }
index 6365d3ed05721711804ea0719101e803d1bdfc1f..b5b0f9a833ce16f9fe66b406691755fe1924a8b0 100644 (file)
@@ -91,5 +91,14 @@ TEST_F(HeaderSearchTest, Dots) {
             "z");
 }
 
+#ifdef _WIN32
+TEST_F(HeaderSearchTest, BackSlash) {
+  addSearchDir("C:\\x\\y\\");
+  EXPECT_EQ(Search.suggestPathToFileForDiagnostics("C:\\x\\y\\z\\t",
+                                                   /*WorkingDir=*/""),
+            "z/t");
+}
+#endif
+
 } // namespace
 } // namespace clang