[clang-tools-extra] 5523fef - [clang][lex] Use preferred path separator in includer-relative lookup

Jan Svoboda via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 8 16:38:15 PDT 2023


Author: Jan Svoboda
Date: 2023-09-08T16:38:08-07:00
New Revision: 5523fefb01c282c4cbcaf6314a9aaf658c6c145f

URL: https://github.com/llvm/llvm-project/commit/5523fefb01c282c4cbcaf6314a9aaf658c6c145f
DIFF: https://github.com/llvm/llvm-project/commit/5523fefb01c282c4cbcaf6314a9aaf658c6c145f.diff

LOG: [clang][lex] Use preferred path separator in includer-relative lookup

There is a long-standing FIXME in `HeaderSearch.cpp` to use the path separator preferred by the platform instead of forward slash. There was an attempt to fix that (1cf6c28a) which got reverted (cf385dc8). I couldn't find an explanation, but my guess is that some tests assuming forward slash started failing.

This commit fixes tests with that assumption.

This is intended to be NFC, but there are two exceptions to that:
* Some diagnostic messages might now contain backslash instead of forward slash.
* Arguments to the "-remap-file" option that use forward slash might stop kicking in. Separators between potential includer path and header name need to be replaced by backslash in that case.

Added: 
    

Modified: 
    clang-tools-extra/test/clang-tidy/checkers/misc/header-include-cycle.cpp
    clang/lib/Lex/HeaderSearch.cpp
    clang/lib/Tooling/Syntax/Tokens.cpp
    clang/test/CXX/class/class.friend/p7-cxx20.cpp
    clang/test/CXX/class/class.mfct/p1-cxx20.cpp
    clang/test/Index/skip-parsed-bodies/compile_commands.json
    clang/test/Misc/remap-file.c
    clang/test/Modules/cxx20-hu-04.cpp
    clang/test/Modules/cxx20-hu-05.cpp
    clang/test/Modules/cxx20-hu-06.cpp
    clang/test/Modules/cxx20-include-translation.cpp
    clang/test/Preprocessor/file_test_windows.c
    clang/test/Preprocessor/microsoft-header-search-fail.c
    clang/unittests/Lex/PPDependencyDirectivesTest.cpp
    clang/unittests/Tooling/TransformerTest.cpp

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/test/clang-tidy/checkers/misc/header-include-cycle.cpp b/clang-tools-extra/test/clang-tidy/checkers/misc/header-include-cycle.cpp
index 57f48d34ecdf691..d3c71ad0750e280 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/misc/header-include-cycle.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/misc/header-include-cycle.cpp
@@ -4,10 +4,10 @@
 // RUN: mkdir %T/misc-header-include-cycle-headers/system
 // RUN: cp -r %S/Inputs/system/header-include-cycle* %T/misc-header-include-cycle-headers/system
 // RUN: cp %s %T/header-include-cycle.cpp
-// RUN: clang-tidy %T/header-include-cycle.cpp -checks='-*,misc-header-include-cycle' -header-filter=.* \
+// RUN: clang-tidy %T%{fs-sep}header-include-cycle.cpp -checks='-*,misc-header-include-cycle' -header-filter=.* \
 // RUN: -config="{CheckOptions: {misc-header-include-cycle.IgnoredFilesList: 'header-include-cycle.self-e.hpp'}}" \
-// RUN: -- -I%T/misc-header-include-cycle-headers -isystem %T/misc-header-include-cycle-headers/system \
-// RUN: --include %T/misc-header-include-cycle-headers/header-include-cycle.self-i.hpp | FileCheck %s \
+// RUN: -- -I%T%{fs-sep}misc-header-include-cycle-headers -isystem %T%{fs-sep}misc-header-include-cycle-headers%{fs-sep}system \
+// RUN: --include %T%{fs-sep}misc-header-include-cycle-headers%{fs-sep}header-include-cycle.self-i.hpp | FileCheck %s \
 // RUN: -check-prefix=CHECK-MESSAGES "-implicit-check-not={{note|warning|error}}:" --dump-input=fail
 // RUN: rm -rf %T/misc-header-include-cycle-headers
 

diff  --git a/clang/lib/Lex/HeaderSearch.cpp b/clang/lib/Lex/HeaderSearch.cpp
index 80e1bad72ce9b78..798a249b4ffa5f9 100644
--- a/clang/lib/Lex/HeaderSearch.cpp
+++ b/clang/lib/Lex/HeaderSearch.cpp
@@ -915,10 +915,8 @@ OptionalFileEntryRef HeaderSearch::LookupFile(
       const FileEntry *Includer = IncluderAndDir.first;
 
       // Concatenate the requested file onto the directory.
-      // FIXME: Portability.  Filename concatenation should be in sys::Path.
       TmpDir = IncluderAndDir.second.getName();
-      TmpDir.push_back('/');
-      TmpDir.append(Filename.begin(), Filename.end());
+      llvm::sys::path::append(TmpDir, Filename);
 
       // FIXME: We don't cache the result of getFileInfo across the call to
       // getFileAndSuggestModule, because it's a reference to an element of

diff  --git a/clang/lib/Tooling/Syntax/Tokens.cpp b/clang/lib/Tooling/Syntax/Tokens.cpp
index 9c2f470e985fb6e..baf9d76b0ba05fe 100644
--- a/clang/lib/Tooling/Syntax/Tokens.cpp
+++ b/clang/lib/Tooling/Syntax/Tokens.cpp
@@ -943,8 +943,8 @@ std::string TokenBuffer::dumpForTests() const {
     auto *Entry = SourceMgr->getFileEntryForID(ID);
     if (!Entry)
       continue; // Skip builtin files.
-    OS << llvm::formatv("file '{0}'\n", Entry->getName())
-       << "  spelled tokens:\n"
+    std::string Path = llvm::sys::path::convert_to_slash(Entry->getName());
+    OS << llvm::formatv("file '{0}'\n", Path) << "  spelled tokens:\n"
        << "    ";
     DumpTokens(OS, File.SpelledTokens);
     OS << "\n";

diff  --git a/clang/test/CXX/class/class.friend/p7-cxx20.cpp b/clang/test/CXX/class/class.friend/p7-cxx20.cpp
index 2baae8cfc37e367..054e6fb3e076ead 100644
--- a/clang/test/CXX/class/class.friend/p7-cxx20.cpp
+++ b/clang/test/CXX/class/class.friend/p7-cxx20.cpp
@@ -27,7 +27,7 @@ class Y {
   friend void y(){};
 };
 
-// CHECK-HU: `-CXXRecordDecl {{.*}} <./header-unit.h:2:1, line:4:1> line:2:7 class Y definition
+// CHECK-HU: `-CXXRecordDecl {{.*}} <.{{/|\\\\?}}header-unit.h:2:1, line:4:1> line:2:7 class Y definition
 // CHECK-HU: |-CXXRecordDecl {{.*}} <col:1, col:7> col:7 implicit class Y
 // CHECK-HU-NEXT: `-FriendDecl {{.*}} <line:3:3, col:19> col:15
 // CHECK-HU-NEXT: `-FunctionDecl {{.*}} parent {{.*}} <col:3, col:19> col:15 friend_undeclared y 'void ()' implicit-inline
@@ -48,7 +48,7 @@ export module M;
 class Z {
   friend void z(){};
 };
-// CHECK-MOD: |-CXXRecordDecl {{.*}} <./header.h:2:1, line:4:1> line:2:7 in M.<global> hidden class A definition
+// CHECK-MOD: |-CXXRecordDecl {{.*}} <.{{/|\\\\?}}header.h:2:1, line:4:1> line:2:7 in M.<global> hidden class A definition
 // CHECK-MOD: | |-CXXRecordDecl {{.*}} <col:1, col:7> col:7 in M.<global> hidden implicit class A
 // CHECK-MOD-NEXT: | `-FriendDecl {{.*}} <line:3:3, col:19> col:15 in M.<global>
 // CHECK-MOD-NEXT: |   `-FunctionDecl {{.*}} parent {{.*}} <col:3, col:19> col:15 in M.<global> hidden friend_undeclared a 'void ()' implicit-inline

diff  --git a/clang/test/CXX/class/class.mfct/p1-cxx20.cpp b/clang/test/CXX/class/class.mfct/p1-cxx20.cpp
index f8c91b139e3ec15..096617f4853bafb 100644
--- a/clang/test/CXX/class/class.mfct/p1-cxx20.cpp
+++ b/clang/test/CXX/class/class.mfct/p1-cxx20.cpp
@@ -27,7 +27,7 @@ class Y {
   void y(){};
 };
 
-// CHECK-HU: `-CXXRecordDecl {{.*}} <./header-unit.h:2:1, line:4:1> line:2:7 class Y definition
+// CHECK-HU: `-CXXRecordDecl {{.*}} <.{{/|\\\\?}}header-unit.h:2:1, line:4:1> line:2:7 class Y definition
 // CHECK-HU: |-CXXRecordDecl {{.*}} <col:1, col:7> col:7 implicit class Y
 // CHECK-HU-NEXT: `-CXXMethodDecl {{.*}} <line:3:3, col:12> col:8 y 'void ()' implicit-inline
 
@@ -48,7 +48,7 @@ class Z {
   void z(){};
 };
 
-// CHECK-MOD: |-CXXRecordDecl {{.*}} <./header.h:2:1, line:4:1> line:2:7 in M.<global> hidden class A definition
+// CHECK-MOD: |-CXXRecordDecl {{.*}} <.{{/|\\\\?}}header.h:2:1, line:4:1> line:2:7 in M.<global> hidden class A definition
 // CHECK-MOD: | |-CXXRecordDecl {{.*}} <col:1, col:7> col:7 in M.<global> hidden implicit class A
 // CHECK-MOD-NEXT: | `-CXXMethodDecl {{.*}} <line:3:3, col:12> col:8 in M.<global> hidden a 'void ()' implicit-inline
 

diff  --git a/clang/test/Index/skip-parsed-bodies/compile_commands.json b/clang/test/Index/skip-parsed-bodies/compile_commands.json
index 21021a9de18071b..991227a843b1d8a 100644
--- a/clang/test/Index/skip-parsed-bodies/compile_commands.json
+++ b/clang/test/Index/skip-parsed-bodies/compile_commands.json
@@ -22,14 +22,14 @@
 // CHECK-NEXT: [enteredMainFile]: t1.cpp
 // CHECK:      [indexDeclaration]: kind: c++-instance-method | name: method_decl | {{.*}} | isRedecl: 0 | isDef: 0 | isContainer: 0
 // CHECK-NEXT: [indexDeclaration]: kind: c++-instance-method | name: method_def1 | {{.*}} | isRedecl: 0 | isDef: 1 | isContainer: 1
-// CHECK-NEXT: [indexEntityReference]: kind: variable | name: some_val | {{.*}} | loc: ./t.h:9:27
+// CHECK-NEXT: [indexEntityReference]: kind: variable | name: some_val | {{.*}} | loc: .{{/|\\\\?}}t.h:9:27
 // CHECK-NEXT: [indexDeclaration]: kind: c++-instance-method | name: method_def2 | {{.*}} | isRedecl: 0 | isDef: 0 | isContainer: 0
 // CHECK-NEXT: [indexDeclaration]: kind: c++-instance-method | name: method_def2 | {{.*}} | isRedecl: 1 | isDef: 1 | isContainer: 1
 // CHECK-NEXT: [indexEntityReference]: kind: namespace | name: NS |
 // CHECK-NEXT: [indexEntityReference]: kind: c++-class | name: C |
-// CHECK-NEXT: [indexEntityReference]: kind: variable | name: some_val | {{.*}} | loc: ./t.h:15:5
+// CHECK-NEXT: [indexEntityReference]: kind: variable | name: some_val | {{.*}} | loc: .{{/|\\\\?}}t.h:15:5
 // CHECK-NEXT: [indexDeclaration]: kind: function | name: foo1 | {{.*}} | isRedecl: 0 | isDef: 1 | isContainer: 1
-// CHECK-NEXT: [indexEntityReference]: kind: variable | name: some_val | {{.*}} | loc: ./t.h:19:5
+// CHECK-NEXT: [indexEntityReference]: kind: variable | name: some_val | {{.*}} | loc: .{{/|\\\\?}}t.h:19:5
 // CHECK-NEXT: [diagnostic]: {{.*}} undeclared identifier 'undef_val1'
 // CHECK-NEXT: [diagnostic]: {{.*}} undeclared identifier 'undef_val2'
 // CHECK-NEXT: [diagnostic]: {{.*}} undeclared identifier 'undef_val3'
@@ -43,13 +43,13 @@
 // CHECK-NEXT: [indexEntityReference]: kind: namespace | name: NS |
 // CHECK-NEXT: [indexEntityReference]: kind: c++-class | name: C |
 // CHECK-NEXT: [indexDeclaration]: kind: function | name: foo1 | {{.*}} | isRedecl: 0 | isDef: 1 | isContainer: skipped
-// CHECK-NEXT: [ppIncludedFile]: ./pragma_once.h
+// CHECK-NEXT: [ppIncludedFile]: .{{/|\\\\?}}pragma_once.h
 // CHECK-NEXT: [indexDeclaration]: kind: function | name: foo2 | {{.*}} | isRedecl: 0 | isDef: 1 | isContainer: 1
-// CHECK-NEXT: [indexEntityReference]: kind: variable | name: some_val | {{.*}} | loc: ./t.h:25:5
+// CHECK-NEXT: [indexEntityReference]: kind: variable | name: some_val | {{.*}} | loc: .{{/|\\\\?}}t.h:25:5
 // CHECK:      [indexDeclaration]: kind: c++-instance-method | name: tsmeth | {{.*}} | isRedecl: 0 | isDef: 1 | isContainer: 1
-// CHECK-NEXT: [indexEntityReference]: kind: variable | name: some_val | {{.*}} | loc: ./pragma_once.h:8:7
+// CHECK-NEXT: [indexEntityReference]: kind: variable | name: some_val | {{.*}} | loc: .{{/|\\\\?}}pragma_once.h:8:7
 // CHECK:      [indexDeclaration]: kind: function | name: imp_foo | {{.*}} | isRedecl: 0 | isDef: 1 | isContainer: 1
-// CHECK-NEXT: [indexEntityReference]: kind: variable | name: some_val | {{.*}} | loc: ./imported.h:4:5
+// CHECK-NEXT: [indexEntityReference]: kind: variable | name: some_val | {{.*}} | loc: .{{/|\\\\?}}imported.h:4:5
 // CHECK-NEXT: [diagnostic]: {{.*}} undeclared identifier 'undef_val4'
 // CHECK-NEXT: [diagnostic]: {{.*}} undeclared identifier 'undef_tsval'
 // CHECK-NEXT: [diagnostic]: {{.*}} undeclared identifier 'undef_impval'
@@ -63,9 +63,9 @@
 // CHECK-NEXT: [indexEntityReference]: kind: namespace | name: NS |
 // CHECK-NEXT: [indexEntityReference]: kind: c++-class | name: C |
 // CHECK-NEXT: [indexDeclaration]: kind: function | name: foo1 | {{.*}} | isRedecl: 0 | isDef: 1 | isContainer: skipped
-// CHECK-NEXT: [ppIncludedFile]: ./pragma_once.h
+// CHECK-NEXT: [ppIncludedFile]: .{{/|\\\\?}}pragma_once.h
 // CHECK-NEXT: [indexDeclaration]: kind: function | name: foo2 | {{.*}} | isRedecl: 0 | isDef: 1 | isContainer: skipped
-// CHECK-NEXT: [indexDeclaration]: kind: variable | {{.*}} | loc: ./pragma_once.h:3:12
+// CHECK-NEXT: [indexDeclaration]: kind: variable | {{.*}} | loc: .{{/|\\\\?}}pragma_once.h:3:12
 // CHECK:      [indexDeclaration]: kind: c++-instance-method | name: tsmeth | {{.*}} | isRedecl: 0 | isDef: 1 | isContainer: skipped
 // CHECK-NOT:  [indexEntityReference]: kind: variable | name: some_val |
 // CHECK:      [indexDeclaration]: kind: function | name: imp_foo | {{.*}} | isRedecl: 0 | isDef: 1 | isContainer: skipped

diff  --git a/clang/test/Misc/remap-file.c b/clang/test/Misc/remap-file.c
index a2a56d9f18b4b6a..d6b925a5e0ab002 100644
--- a/clang/test/Misc/remap-file.c
+++ b/clang/test/Misc/remap-file.c
@@ -1,6 +1,6 @@
 // RUN: %clang_cc1 -remap-file "%s;%S/Inputs/remapped-file" -fsyntax-only %s 2>&1 | FileCheck -check-prefix=CHECK-EXIST %s
 // RUN: %clang_cc1 -remap-file "%S/nonexistent.c;%S/Inputs/remapped-file" -fsyntax-only %S/nonexistent.c 2>&1 | FileCheck -check-prefix=CHECK-NONEXIST %s
-// RUN: %clang_cc1 -remap-file "%S/nonexistent.c;%S/Inputs/remapped-file-2" -remap-file "%S/nonexistent.h;%S/Inputs/remapped-file-3" -fsyntax-only %S/nonexistent.c 2>&1 | FileCheck -check-prefix=CHECK-HEADER %s
+// RUN: %clang_cc1 -remap-file "%S/nonexistent.c;%S/Inputs/remapped-file-2" -remap-file "%S%{fs-sep}nonexistent.h;%S/Inputs/remapped-file-3" -fsyntax-only %S/nonexistent.c 2>&1 | FileCheck -check-prefix=CHECK-HEADER %s
 
 // CHECK-EXIST: remap-file.c:1:28: warning: incompatible pointer types
 // CHECK-NONEXIST: nonexistent.c:1:28: warning: incompatible pointer types

diff  --git a/clang/test/Modules/cxx20-hu-04.cpp b/clang/test/Modules/cxx20-hu-04.cpp
index aed1bdb875ec974..8546b33572dc83f 100644
--- a/clang/test/Modules/cxx20-hu-04.cpp
+++ b/clang/test/Modules/cxx20-hu-04.cpp
@@ -39,7 +39,7 @@ int baz(int);
 // expected-no-diagnostics
 
 // CHECK-HU:  ====== C++20 Module structure ======
-// CHECK-HU-NEXT:  Header Unit './hu-01.h' is the Primary Module at index #1
+// CHECK-HU-NEXT:  Header Unit '.{{/|\\\\?}}hu-01.h' is the Primary Module at index #1
 
 //--- hu-02.h
 export import "hu-01.h"; // expected-warning {{the implementation of header units is in an experimental phase}}
@@ -73,11 +73,11 @@ inline int bar(int x) {
 }
 #endif
 
-// CHECK-IMP: remark: importing module './hu-01.h' from 'hu-01.pcm'
+// CHECK-IMP: remark: importing module '.{{/|\\\\?}}hu-01.h' from 'hu-01.pcm'
 // CHECK-HU2:  ====== C++20 Module structure ======
-// CHECK-HU2-NEXT:  Header Unit './hu-02.h' is the Primary Module at index #2
+// CHECK-HU2-NEXT:  Header Unit '.{{/|\\\\?}}hu-02.h' is the Primary Module at index #2
 // CHECK-HU2-NEXT:   Exports:
-// CHECK-HU2-NEXT:    Header Unit './hu-01.h' is at index #1
+// CHECK-HU2-NEXT:    Header Unit '.{{/|\\\\?}}hu-01.h' is at index #1
 // expected-no-diagnostics
 
 //--- importer-01.cpp
@@ -101,5 +101,5 @@ int success(int x) {
   return foo(FORTYTWO + x + KAP);
 }
 
-// CHECK-IMP-HU2: remark: importing module './hu-02.h' from 'hu-02.pcm'
-// CHECK-IMP-HU2: remark: importing module './hu-01.h' into './hu-02.h' from '[[TDIR]]{{[/\\]}}hu-01.pcm'
+// CHECK-IMP-HU2: remark: importing module '.{{/|\\\\?}}hu-02.h' from 'hu-02.pcm'
+// CHECK-IMP-HU2: remark: importing module '.{{/|\\\\?}}hu-01.h' into '.{{/|\\\\?}}hu-02.h' from '[[TDIR]]{{[/\\]}}hu-01.pcm'

diff  --git a/clang/test/Modules/cxx20-hu-05.cpp b/clang/test/Modules/cxx20-hu-05.cpp
index b0d7c0f3c9e76de..8147da72fb25532 100644
--- a/clang/test/Modules/cxx20-hu-05.cpp
+++ b/clang/test/Modules/cxx20-hu-05.cpp
@@ -29,4 +29,4 @@ int baz(int);
 #endif // __GUARD
 
 // CHECK-HU:  ====== C++20 Module structure ======
-// CHECK-HU-NEXT:  Header Unit './hu-01.h' is the Primary Module at index #1
+// CHECK-HU-NEXT:  Header Unit '.{{/|\\\\?}}hu-01.h' is the Primary Module at index #1

diff  --git a/clang/test/Modules/cxx20-hu-06.cpp b/clang/test/Modules/cxx20-hu-06.cpp
index 1048e4916452320..ccbae155e8d6dc4 100644
--- a/clang/test/Modules/cxx20-hu-06.cpp
+++ b/clang/test/Modules/cxx20-hu-06.cpp
@@ -65,4 +65,4 @@ inline int bar(int x) {
   return FORTYTWO;
 }
 #endif
-// CHECK-IMP: remark: importing module './hu-01.h' from 'hu-01.pcm'
+// CHECK-IMP: remark: importing module '.{{/|\\\\?}}hu-01.h' from 'hu-01.pcm'

diff  --git a/clang/test/Modules/cxx20-include-translation.cpp b/clang/test/Modules/cxx20-include-translation.cpp
index 2528e831d808848..b36eb176c40a612 100644
--- a/clang/test/Modules/cxx20-include-translation.cpp
+++ b/clang/test/Modules/cxx20-include-translation.cpp
@@ -81,7 +81,7 @@ module /*nothing here*/;
 
 // This should be include-translated, when the header unit for h1 is available.
  // expected-warning at +1 {{the implementation of header units is in an experimental phase}}
-#include "h1.h" // expected-remark {{treating #include as an import of module './h1.h'}}
+#include "h1.h" // expected-remark-re {{treating #include as an import of module '.{{/|\\\\?}}h1.h'}}
 // Import of a header unit is allowed, named modules are not.
 import "h2.h"; // expected-warning {{the implementation of header units is in an experimental phase}}
 // A regular, untranslated, header
@@ -104,7 +104,7 @@ export void charlie() {
   five();
 }
 
-// CHECK: #pragma clang module import "./h1.h"
-// CHECK: import ./h2.h
-// CHECK: import ./h3.h
-// CHECK-NOT: #pragma clang module import "./h4.h"
+// CHECK: #pragma clang module import ".{{/|\\\\?}}h1.h"
+// CHECK: import .{{/|\\\\?}}h2.h
+// CHECK: import .{{/|\\\\?}}h3.h
+// CHECK-NOT: #pragma clang module import ".{{/|\\\\?}}h4.h"

diff  --git a/clang/test/Preprocessor/file_test_windows.c b/clang/test/Preprocessor/file_test_windows.c
index 7cc8a8d9e4a2ccc..89324001330e275 100644
--- a/clang/test/Preprocessor/file_test_windows.c
+++ b/clang/test/Preprocessor/file_test_windows.c
@@ -25,12 +25,12 @@ filename: __FILE__
 #include "Inputs/include-file-test/file_test.h"
 
 // CHECK: filename: "A:\\UNLIKELY_PATH\\empty\\file_test_windows.c"
-// CHECK: filename: "A:\\UNLIKELY_PATH\\empty/Inputs/include-file-test/file_test.h"
+// CHECK: filename: "A:\\UNLIKELY_PATH\\empty\\Inputs/include-file-test/file_test.h"
 // CHECK: basefile: "A:\\UNLIKELY_PATH\\empty\\file_test_windows.c"
 // CHECK-NOT: filename:
 
 // CHECK-EVIL: filename: "A:\\UNLIKELY_PATH=empty\\file_test_windows.c"
-// CHECK-EVIL: filename: "A:\\UNLIKELY_PATH=empty/Inputs/include-file-test/file_test.h"
+// CHECK-EVIL: filename: "A:\\UNLIKELY_PATH=empty\\Inputs/include-file-test/file_test.h"
 // CHECK-EVIL: basefile: "A:\\UNLIKELY_PATH=empty\\file_test_windows.c"
 // CHECK-EVIL-NOT: filename:
 

diff  --git a/clang/test/Preprocessor/microsoft-header-search-fail.c b/clang/test/Preprocessor/microsoft-header-search-fail.c
index 1468fc5445b6003..c377cb11d658aa9 100644
--- a/clang/test/Preprocessor/microsoft-header-search-fail.c
+++ b/clang/test/Preprocessor/microsoft-header-search-fail.c
@@ -7,7 +7,7 @@
 #include "x/header.h"
 #include "z/header.h"
 
-// expected-warning-re at include/y/header.h:1 {{#include resolved using non-portable Microsoft search rules as: {{.*}}x/culprit.h}}
+// expected-warning-re at include/y/header.h:1 {{#include resolved using non-portable Microsoft search rules as: {{.*}}x{{/|\\\\?}}culprit.h}}
 // expected-error at include/z/header.h:1 {{'culprit.h' file not found}}
 
 //--- include/x/header.h

diff  --git a/clang/unittests/Lex/PPDependencyDirectivesTest.cpp b/clang/unittests/Lex/PPDependencyDirectivesTest.cpp
index 2a3f241a7528b5e..4685021b6ecdbae 100644
--- a/clang/unittests/Lex/PPDependencyDirectivesTest.cpp
+++ b/clang/unittests/Lex/PPDependencyDirectivesTest.cpp
@@ -140,10 +140,14 @@ TEST_F(PPDependencyDirectivesTest, MacroGuard) {
       break;
   }
 
-  SmallVector<StringRef> ExpectedIncludes{
+  SmallVector<std::string> IncludedFilesSlash;
+  for (StringRef IncludedFile : IncludedFiles)
+    IncludedFilesSlash.push_back(
+        llvm::sys::path::convert_to_slash(IncludedFile));
+  SmallVector<std::string> ExpectedIncludes{
       "main.c", "./head1.h", "./head2.h", "./head2.h", "./head3.h", "./head3.h",
   };
-  EXPECT_EQ(IncludedFiles, ExpectedIncludes);
+  EXPECT_EQ(IncludedFilesSlash, ExpectedIncludes);
 }
 
 } // anonymous namespace

diff  --git a/clang/unittests/Tooling/TransformerTest.cpp b/clang/unittests/Tooling/TransformerTest.cpp
index 09fcf04a0d3f687..cbd84ab794a49af 100644
--- a/clang/unittests/Tooling/TransformerTest.cpp
+++ b/clang/unittests/Tooling/TransformerTest.cpp
@@ -1623,7 +1623,8 @@ TEST_F(TransformerTest, MultipleFiles) {
     return L.getFilePath() < R.getFilePath();
   });
 
-  ASSERT_EQ(Changes[0].getFilePath(), "./input.h");
+  ASSERT_EQ(llvm::sys::path::convert_to_slash(Changes[0].getFilePath()),
+            "./input.h");
   EXPECT_THAT(Changes[0].getInsertedHeaders(), IsEmpty());
   EXPECT_THAT(Changes[0].getRemovedHeaders(), IsEmpty());
   llvm::Expected<std::string> UpdatedCode =
@@ -1660,7 +1661,8 @@ TEST_F(TransformerTest, AddIncludeMultipleFiles) {
       {{"input.h", Header}}));
 
   ASSERT_EQ(Changes.size(), 1U);
-  ASSERT_EQ(Changes[0].getFilePath(), "./input.h");
+  ASSERT_EQ(llvm::sys::path::convert_to_slash(Changes[0].getFilePath()),
+            "./input.h");
   EXPECT_THAT(Changes[0].getInsertedHeaders(), ElementsAre("header.h"));
   EXPECT_THAT(Changes[0].getRemovedHeaders(), IsEmpty());
   llvm::Expected<std::string> UpdatedCode =
@@ -1702,14 +1704,14 @@ TEST_F(TransformerTest, MultiFileEdit) {
       "clang-tool", std::make_shared<PCHContainerOperations>(),
       {{"input.h", Header}}));
 
+  auto GetPathWithSlashes = [](const AtomicChange &C) {
+    return llvm::sys::path::convert_to_slash(C.getFilePath());
+  };
+
   EXPECT_EQ(ErrorCount, 0);
-  EXPECT_THAT(
-      ChangeSets,
-      UnorderedElementsAre(UnorderedElementsAre(
-          ResultOf([](const AtomicChange &C) { return C.getFilePath(); },
-                   "input.cc"),
-          ResultOf([](const AtomicChange &C) { return C.getFilePath(); },
-                   "./input.h"))));
+  EXPECT_THAT(ChangeSets, UnorderedElementsAre(UnorderedElementsAre(
+                              ResultOf(GetPathWithSlashes, "input.cc"),
+                              ResultOf(GetPathWithSlashes, "./input.h"))));
 }
 
 TEST_F(TransformerTest, GeneratesMetadata) {


        


More information about the cfe-commits mailing list