diff --git a/clang-tools-extra/clang-tidy/google/UpgradeGoogletestCaseCheck.cpp b/clang-tools-extra/clang-tidy/google/UpgradeGoogletestCaseCheck.cpp --- a/clang-tools-extra/clang-tidy/google/UpgradeGoogletestCaseCheck.cpp +++ b/clang-tools-extra/clang-tidy/google/UpgradeGoogletestCaseCheck.cpp @@ -67,7 +67,9 @@ // recent enough version of Google Test. llvm::StringRef FileName = PP->getSourceManager().getFilename( MD->getMacroInfo()->getDefinitionLoc()); - ReplacementFound = FileName.endswith("gtest/gtest-typed-test.h") && + SmallString<32> TypedTestFileName("gtest/gtest-typed-test.h"); + llvm::sys::path::make_preferred(TypedTestFileName); + ReplacementFound = FileName.endswith(TypedTestFileName) && PP->getSpelling(MacroNameTok) == "TYPED_TEST_SUITE"; } } @@ -103,7 +105,9 @@ llvm::StringRef FileName = PP->getSourceManager().getFilename( MD.getMacroInfo()->getDefinitionLoc()); - if (!FileName.endswith("gtest/gtest-typed-test.h")) + SmallString<32> TypedTestFileName("gtest/gtest-typed-test.h"); + llvm::sys::path::make_preferred(TypedTestFileName); + if (!FileName.endswith(TypedTestFileName)) return; DiagnosticBuilder Diag = Check->diag(Loc, RenameCaseToSuiteMessage); diff --git a/clang-tools-extra/test/clang-apply-replacements/conflict.cpp b/clang-tools-extra/test/clang-apply-replacements/conflict.cpp --- a/clang-tools-extra/test/clang-apply-replacements/conflict.cpp +++ b/clang-tools-extra/test/clang-apply-replacements/conflict.cpp @@ -4,7 +4,8 @@ // RUN: sed "s#\$(path)#%/S/Inputs/conflict#" %S/Inputs/conflict/file3.yaml > %T/Inputs/conflict/file3.yaml // RUN: sed "s#\$(path)#%/S/Inputs/conflict#" %S/Inputs/conflict/expected.txt > %T/Inputs/conflict/expected.txt // RUN: not clang-apply-replacements %T/Inputs/conflict > %T/Inputs/conflict/output.txt 2>&1 -// RUN: diff -b %T/Inputs/conflict/output.txt %T/Inputs/conflict/expected.txt +// RUN: sed 's#\\#/#g' %T/Inputs/conflict/output.txt > %T/Inputs/conflict/output-u.txt +// RUN: diff -b %T/Inputs/conflict/output-u.txt %T/Inputs/conflict/expected.txt // // Check that the yaml files are *not* deleted after running clang-apply-replacements without remove-change-desc-files even when there is a failure. // RUN: ls -1 %T/Inputs/conflict | FileCheck %s --check-prefix=YAML diff --git a/clang-tools-extra/test/clang-apply-replacements/order-dependent.cpp b/clang-tools-extra/test/clang-apply-replacements/order-dependent.cpp --- a/clang-tools-extra/test/clang-apply-replacements/order-dependent.cpp +++ b/clang-tools-extra/test/clang-apply-replacements/order-dependent.cpp @@ -4,4 +4,5 @@ // RUN: sed "s#\$(path)#%/T/Inputs/order-dependent#" %S/Inputs/order-dependent/file2.yaml > %T/Inputs/order-dependent/file2.yaml // RUN: sed "s#\$(path)#%/T/Inputs/order-dependent#" %S/Inputs/order-dependent/expected.txt > %T/Inputs/order-dependent/expected.txt // RUN: not clang-apply-replacements %T/Inputs/order-dependent > %T/Inputs/order-dependent/output.txt 2>&1 -// RUN: diff -b %T/Inputs/order-dependent/output.txt %T/Inputs/order-dependent/expected.txt +// RUN: sed 's#\\#/#g' %T/Inputs/order-dependent/output.txt > %T/Inputs/order-dependent/output-u.txt +// RUN: diff -b %T/Inputs/order-dependent/output-u.txt %T/Inputs/order-dependent/expected.txt diff --git a/clang-tools-extra/test/clang-tidy/checkers/abseil-no-internal-dependencies.cpp b/clang-tools-extra/test/clang-tidy/checkers/abseil-no-internal-dependencies.cpp --- a/clang-tools-extra/test/clang-tidy/checkers/abseil-no-internal-dependencies.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/abseil-no-internal-dependencies.cpp @@ -6,7 +6,7 @@ // CHECK-NOT: warning: #include "absl/external-file.h" -// CHECK: absl/external-file.h:6:24: warning: do not reference any 'internal' namespaces; those implementation details are reserved to Abseil [abseil-no-internal-dependencies] +// CHECK: absl{{[/\\]}}external-file.h:6:24: warning: do not reference any 'internal' namespaces; those implementation details are reserved to Abseil [abseil-no-internal-dependencies] void DirectAcess() { absl::strings_internal::InternalFunction(); diff --git a/clang-tools-extra/test/clang-tidy/checkers/abseil-no-namespace.cpp b/clang-tools-extra/test/clang-tidy/checkers/abseil-no-namespace.cpp --- a/clang-tools-extra/test/clang-tidy/checkers/abseil-no-namespace.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/abseil-no-namespace.cpp @@ -7,7 +7,7 @@ /// Warning will be triggered on code that is not internal that is included. #include "absl/external-file.h" -// CHECK: absl/external-file.h:1:11: warning: namespace 'absl' is reserved +// CHECK: absl{{[/\\]}}external-file.h:1:11: warning: namespace 'absl' is reserved namespace absl {} // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: namespace 'absl' is reserved for implementation of the Abseil library and should not be opened in user code [abseil-no-namespace] diff --git a/clang/bindings/python/tests/cindex/test_translation_unit.py b/clang/bindings/python/tests/cindex/test_translation_unit.py --- a/clang/bindings/python/tests/cindex/test_translation_unit.py +++ b/clang/bindings/python/tests/cindex/test_translation_unit.py @@ -85,7 +85,7 @@ int x; int SOME_DEFINE; """), - ('./fake.h', """ + ('fake.h', """ #define SOME_DEFINE y """) ]) diff --git a/clang/lib/Basic/FileManager.cpp b/clang/lib/Basic/FileManager.cpp --- a/clang/lib/Basic/FileManager.cpp +++ b/clang/lib/Basic/FileManager.cpp @@ -136,6 +136,13 @@ ++NumDirLookups; + SmallString<128> CleanDirName; + if (DirName.size() > 1) { + CleanDirName = DirName; + llvm::sys::path::remove_dots(CleanDirName); + DirName = CleanDirName; + } + // See if there was already an entry in the map. Note that the map // contains both virtual and real directories. auto SeenDirInsertResult = @@ -205,6 +212,11 @@ FileManager::getFileRef(StringRef Filename, bool openFile, bool CacheFailure) { ++NumFileLookups; + SmallString<128> CleanFilename = Filename; + // Explicitly not removing "../" because doing so can break symlinks. + llvm::sys::path::remove_dots(CleanFilename, /*remove_dot_dot=*/false); + Filename = CleanFilename; + // See if there is already an entry in the map. auto SeenFileInsertResult = SeenFileEntries.insert({Filename, std::errc::no_such_file_or_directory}); diff --git a/clang/test/ClangScanDeps/header-search-pruning-transitive.c b/clang/test/ClangScanDeps/header-search-pruning-transitive.c --- a/clang/test/ClangScanDeps/header-search-pruning-transitive.c +++ b/clang/test/ClangScanDeps/header-search-pruning-transitive.c @@ -72,8 +72,8 @@ // CHECK: ], // CHECK-NEXT: "context-hash": "[[HASH_X:.*]]", // CHECK-NEXT: "file-deps": [ -// CHECK-NEXT: "[[PREFIX]]/./X.h", -// CHECK-NEXT: "[[PREFIX]]/./module.modulemap" +// CHECK-NEXT: "[[PREFIX]]/X.h", +// CHECK-NEXT: "[[PREFIX]]/module.modulemap" // CHECK-NEXT: ], // CHECK-NEXT: "name": "X" // CHECK-NEXT: }, @@ -84,11 +84,11 @@ // CHECK: ], // CHECK-NEXT: "context-hash": "[[HASH_Y_WITH_A]]", // CHECK-NEXT: "file-deps": [ -// CHECK-NEXT: "[[PREFIX]]/./Y.h", -// CHECK-NEXT: "[[PREFIX]]/./a/a.h", -// CHECK-NEXT: "[[PREFIX]]/./begin/begin.h", -// CHECK-NEXT: "[[PREFIX]]/./end/end.h", -// CHECK-NEXT: "[[PREFIX]]/./module.modulemap" +// CHECK-NEXT: "[[PREFIX]]/Y.h", +// CHECK-NEXT: "[[PREFIX]]/a/a.h", +// CHECK-NEXT: "[[PREFIX]]/begin/begin.h", +// CHECK-NEXT: "[[PREFIX]]/end/end.h", +// CHECK-NEXT: "[[PREFIX]]/module.modulemap" // CHECK-NEXT: ], // CHECK-NEXT: "name": "Y" // CHECK-NEXT: } @@ -127,8 +127,8 @@ // also has a different context hash from the first version of module X. // CHECK-NOT: "context-hash": "[[HASH_X]]", // CHECK: "file-deps": [ -// CHECK-NEXT: "[[PREFIX]]/./X.h", -// CHECK-NEXT: "[[PREFIX]]/./module.modulemap" +// CHECK-NEXT: "[[PREFIX]]/X.h", +// CHECK-NEXT: "[[PREFIX]]/module.modulemap" // CHECK-NEXT: ], // CHECK-NEXT: "name": "X" // CHECK-NEXT: }, @@ -139,10 +139,10 @@ // CHECK: ], // CHECK-NEXT: "context-hash": "[[HASH_Y_WITHOUT_A]]", // CHECK-NEXT: "file-deps": [ -// CHECK-NEXT: "[[PREFIX]]/./Y.h", -// CHECK-NEXT: "[[PREFIX]]/./begin/begin.h", -// CHECK-NEXT: "[[PREFIX]]/./end/end.h", -// CHECK-NEXT: "[[PREFIX]]/./module.modulemap" +// CHECK-NEXT: "[[PREFIX]]/Y.h", +// CHECK-NEXT: "[[PREFIX]]/begin/begin.h", +// CHECK-NEXT: "[[PREFIX]]/end/end.h", +// CHECK-NEXT: "[[PREFIX]]/module.modulemap" // CHECK-NEXT: ], // CHECK-NEXT: "name": "Y" // CHECK-NEXT: } diff --git a/clang/test/Frontend/dependency-gen.c b/clang/test/Frontend/dependency-gen.c --- a/clang/test/Frontend/dependency-gen.c +++ b/clang/test/Frontend/dependency-gen.c @@ -16,7 +16,7 @@ // RUN: %clang -MD -MF - %s -fsyntax-only -I .//./a/b/ | FileCheck -check-prefix=CHECK-FOUR %s // CHECK-FOUR: {{ }}a{{[/\\]}}b{{[/\\]}}x.h // RUN: %clang -MD -MF - %s -fsyntax-only -I a/b/. | FileCheck -check-prefix=CHECK-FIVE %s -// CHECK-FIVE: {{ }}a{{[/\\]}}b{{[/\\]}}.{{[/\\]}}x.h +// CHECK-FIVE: {{ }}a{{[/\\]}}b{{[/\\]}}x.h // RUN: cd a/b // RUN: %clang -MD -MF - %s -fsyntax-only -I ./ | FileCheck -check-prefix=CHECK-SIX %s // CHECK-SIX: {{ }}x.h diff --git a/clang/test/Index/skip-parsed-bodies/compile_commands.json b/clang/test/Index/skip-parsed-bodies/compile_commands.json --- 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/Modules/cxx20-hu-04.cpp b/clang/test/Modules/cxx20-hu-04.cpp --- a/clang/test/Modules/cxx20-hu-04.cpp +++ b/clang/test/Modules/cxx20-hu-04.cpp @@ -39,7 +39,7 @@ // 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"; @@ -73,11 +73,11 @@ } #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 @@ 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 --- a/clang/test/Modules/cxx20-hu-05.cpp +++ b/clang/test/Modules/cxx20-hu-05.cpp @@ -29,4 +29,4 @@ #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 --- a/clang/test/Modules/cxx20-hu-06.cpp +++ b/clang/test/Modules/cxx20-hu-06.cpp @@ -65,4 +65,4 @@ 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/filename.cpp b/clang/test/Modules/filename.cpp --- a/clang/test/Modules/filename.cpp +++ b/clang/test/Modules/filename.cpp @@ -5,4 +5,4 @@ // Make sure that headers that are referenced by module maps have __FILE__ // reflect the include path they were found with. -// CHECK: const char *p = "./Inputs/filename/a.h" +// CHECK: const char *p = "Inputs/filename/a.h" diff --git a/clang/unittests/Lex/HeaderSearchTest.cpp b/clang/unittests/Lex/HeaderSearchTest.cpp --- a/clang/unittests/Lex/HeaderSearchTest.cpp +++ b/clang/unittests/Lex/HeaderSearchTest.cpp @@ -112,6 +112,23 @@ } TEST_F(HeaderSearchTest, Dots) { + VFS->addFile("./inc/./foo.h", 0, nullptr, /*User=*/None, /*Group=*/None, + llvm::sys::fs::file_type::regular_file); + llvm::Expected FileRef = FileMgr.getFileRef("inc/foo.h", false); + assert(FileRef); + const auto *const FE = &FileRef->getFileEntry(); + EXPECT_EQ(StringRef(FileRef->getName()), StringRef("inc/foo.h")); + + FileRef = FileMgr.getFileRef("./inc/./foo.h", false); + assert(FileRef); + EXPECT_EQ(StringRef(FileRef->getName()), StringRef("inc/foo.h")); + EXPECT_EQ(FE, &FileRef->getFileEntry()); + + FileRef = FileMgr.getFileRef("inc/./foo.h", false); + assert(FileRef); + EXPECT_EQ(StringRef(FileRef->getName()), StringRef("inc/foo.h")); + EXPECT_EQ(FE, &FileRef->getFileEntry()); + addSearchDir("/x/./y/"); EXPECT_EQ(Search.suggestPathToFileForDiagnostics("/x/y/./z", /*WorkingDir=*/"", diff --git a/clang/unittests/Tooling/Syntax/TokensTest.cpp b/clang/unittests/Tooling/Syntax/TokensTest.cpp --- a/clang/unittests/Tooling/Syntax/TokensTest.cpp +++ b/clang/unittests/Tooling/Syntax/TokensTest.cpp @@ -292,7 +292,7 @@ {"int main() {}", R"(expanded tokens: int main ( ) { } -file './input.cpp' +file 'input.cpp' spelled tokens: int main ( ) { } no mappings. @@ -301,7 +301,7 @@ {"\t\n int\t\n main\t\n (\t\n )\t\n{\t\n }\t\n", R"(expanded tokens: int main ( ) { } -file './input.cpp' +file 'input.cpp' spelled tokens: int main ( ) { } no mappings. @@ -313,7 +313,7 @@ )cpp", R"(expanded tokens: -file './input.cpp' +file 'input.cpp' spelled tokens: # pragma GCC visibility push ( public ) # pragma GCC visibility pop mappings: @@ -322,7 +322,7 @@ // Empty files should not crash. {R"cpp()cpp", R"(expanded tokens: -file './input.cpp' +file 'input.cpp' spelled tokens: no mappings. @@ -336,7 +336,7 @@ )cpp", R"(expanded tokens: a -file './input.cpp' +file 'input.cpp' spelled tokens: a # define MACRO ( ) A # B mappings: @@ -401,7 +401,7 @@ std::string Expected = "expanded tokens:\n" " int a ;\n" - "file './input.cpp'\n" + "file 'input.cpp'\n" " spelled tokens:\n" " # define FOO a # include \"unresolved_file.h\" # undef FOO " "# ifdef X # else # endif # ifndef Y # endif # if 1 # elif 2 # else " @@ -420,7 +420,7 @@ )cpp", R"(expanded tokens: int const a ; -file './input.cpp' +file 'input.cpp' spelled tokens: # define INT int const INT a ; mappings: @@ -434,7 +434,7 @@ )cpp", R"(expanded tokens: const int a ; -file './input.cpp' +file 'input.cpp' spelled tokens: # define INT ( a ) const int INT ( 10 + 10 ) a ; mappings: @@ -449,7 +449,7 @@ )cpp", R"(expanded tokens: int const a ; -file './input.cpp' +file 'input.cpp' spelled tokens: # define ID ( X ) X # define INT int const ID ( ID ( INT ) ) a ; mappings: @@ -465,7 +465,7 @@ )cpp", "expanded tokens:\n" " int a = 1 * 2 + 3 * 4 + 5 ;\n" - "file './input.cpp'\n" + "file 'input.cpp'\n" " spelled tokens:\n" " # define ADD ( X , Y ) X + Y # define MULT ( X , Y ) X * Y int " "a = ADD ( MULT ( 1 , 2 ) , MULT ( 3 , ADD ( 4 , 5 ) ) ) ;\n" @@ -482,7 +482,7 @@ )cpp", R"(expanded tokens: -file './input.cpp' +file 'input.cpp' spelled tokens: # define EMPTY # define EMPTY_FUNC ( X ) EMPTY EMPTY_FUNC ( 1 + 2 + 3 ) mappings: @@ -497,7 +497,7 @@ )cpp", R"(expanded tokens: int a = 10 + 10 ; -file './input.cpp' +file 'input.cpp' spelled tokens: # define FOO 10 + 10 ; int a = FOO mappings: @@ -512,7 +512,7 @@ )cpp", R"(expanded tokens: 1 + 42 -file './input.cpp' +file 'input.cpp' spelled tokens: # define NUM 42 # define ID ( a ) a # define M 1 + ID M ( NUM ) mappings: @@ -601,19 +601,19 @@ std::string Expected = R"(expanded tokens: int a = 100 ; int b = 1 + 2 ; int c = 1 + 2 * 3 ; -file './input.cpp' +file 'input.cpp' spelled tokens: # include "foo.h" int c = ADD ( 1 , MULT ( 2 , 3 ) ) ; mappings: ['#'_0, 'int'_3) => ['int'_12, 'int'_12) ['ADD'_6, ';'_17) => ['1'_15, ';'_20) -file './foo.h' +file 'foo.h' spelled tokens: # define ADD ( X , Y ) X + Y int a = 100 ; # include "bar.h" mappings: ['#'_0, 'int'_11) => ['int'_0, 'int'_0) ['#'_16, ''_19) => ['int'_5, 'int'_5) -file './bar.h' +file 'bar.h' spelled tokens: int b = ADD ( 1 , 2 ) ; # define MULT ( X , Y ) X * Y mappings: diff --git a/clang/unittests/Tooling/TransformerTest.cpp b/clang/unittests/Tooling/TransformerTest.cpp --- a/clang/unittests/Tooling/TransformerTest.cpp +++ b/clang/unittests/Tooling/TransformerTest.cpp @@ -1622,21 +1622,22 @@ return L.getFilePath() < R.getFilePath(); }); - ASSERT_EQ(Changes[0].getFilePath(), "./input.h"); - EXPECT_THAT(Changes[0].getInsertedHeaders(), IsEmpty()); - EXPECT_THAT(Changes[0].getRemovedHeaders(), IsEmpty()); + const auto &change_h = Changes[1]; + ASSERT_EQ(change_h.getFilePath(), "input.h"); + EXPECT_THAT(change_h.getInsertedHeaders(), IsEmpty()); + EXPECT_THAT(change_h.getRemovedHeaders(), IsEmpty()); llvm::Expected UpdatedCode = - clang::tooling::applyAllReplacements(Header, - Changes[0].getReplacements()); + clang::tooling::applyAllReplacements(Header, change_h.getReplacements()); ASSERT_TRUE(static_cast(UpdatedCode)) << "Could not update code: " << llvm::toString(UpdatedCode.takeError()); EXPECT_EQ(format(*UpdatedCode), ""); - ASSERT_EQ(Changes[1].getFilePath(), "input.cc"); - EXPECT_THAT(Changes[1].getInsertedHeaders(), IsEmpty()); - EXPECT_THAT(Changes[1].getRemovedHeaders(), IsEmpty()); - UpdatedCode = clang::tooling::applyAllReplacements( - Source, Changes[1].getReplacements()); + const auto &change_cc = Changes[0]; + ASSERT_EQ(change_cc.getFilePath(), "input.cc"); + EXPECT_THAT(change_cc.getInsertedHeaders(), IsEmpty()); + EXPECT_THAT(change_cc.getRemovedHeaders(), IsEmpty()); + UpdatedCode = + clang::tooling::applyAllReplacements(Source, change_cc.getReplacements()); ASSERT_TRUE(static_cast(UpdatedCode)) << "Could not update code: " << llvm::toString(UpdatedCode.takeError()); EXPECT_EQ(format(*UpdatedCode), format("#include \"input.h\"\n")); @@ -1659,7 +1660,7 @@ {{"input.h", Header}})); ASSERT_EQ(Changes.size(), 1U); - ASSERT_EQ(Changes[0].getFilePath(), "./input.h"); + ASSERT_EQ(Changes[0].getFilePath(), "input.h"); EXPECT_THAT(Changes[0].getInsertedHeaders(), ElementsAre("header.h")); EXPECT_THAT(Changes[0].getRemovedHeaders(), IsEmpty()); llvm::Expected UpdatedCode = @@ -1708,7 +1709,7 @@ ResultOf([](const AtomicChange &C) { return C.getFilePath(); }, "input.cc"), ResultOf([](const AtomicChange &C) { return C.getFilePath(); }, - "./input.h")))); + "input.h")))); } TEST_F(TransformerTest, GeneratesMetadata) {