Author: Ishaan Gandhi Date: 2022-04-25T20:40:56+02:00 New Revision: 87468e85fcdcf1bd5055466e34d17436a79017a2
URL: https://github.com/llvm/llvm-project/commit/87468e85fcdcf1bd5055466e34d17436a79017a2 DIFF: https://github.com/llvm/llvm-project/commit/87468e85fcdcf1bd5055466e34d17436a79017a2.diff LOG: compile commands header to source heuristic lower-cases filenames before inferring file types This leads to ".C" files being rewritten as ".c" files and being inferred to be "c" files as opposed to "c++" files. Fixes https://github.com/clangd/clangd/issues/1108 Reviewed By: sammccall Differential Revision: https://reviews.llvm.org/D124262 Added: Modified: clang/lib/Tooling/InterpolatingCompilationDatabase.cpp clang/unittests/Tooling/CompilationDatabaseTest.cpp Removed: ################################################################################ diff --git a/clang/lib/Tooling/InterpolatingCompilationDatabase.cpp b/clang/lib/Tooling/InterpolatingCompilationDatabase.cpp index 51e8439b6b79b..0143b5f8df6b6 100644 --- a/clang/lib/Tooling/InterpolatingCompilationDatabase.cpp +++ b/clang/lib/Tooling/InterpolatingCompilationDatabase.cpp @@ -328,7 +328,7 @@ class FileIndex { StringRef Path = Strings.save(StringRef(OriginalPaths[I]).lower()); Paths.emplace_back(Path, I); - Types.push_back(foldType(guessType(Path))); + Types.push_back(foldType(guessType(OriginalPaths[I]))); Stems.emplace_back(sys::path::stem(Path), I); auto Dir = ++sys::path::rbegin(Path), DirEnd = sys::path::rend(Path); for (int J = 0; J < DirectorySegmentsIndexed && Dir != DirEnd; ++J, ++Dir) diff --git a/clang/unittests/Tooling/CompilationDatabaseTest.cpp b/clang/unittests/Tooling/CompilationDatabaseTest.cpp index adb9de0c1cbaa..8194dd3953c20 100644 --- a/clang/unittests/Tooling/CompilationDatabaseTest.cpp +++ b/clang/unittests/Tooling/CompilationDatabaseTest.cpp @@ -836,6 +836,14 @@ TEST_F(InterpolateTest, Case) { EXPECT_EQ(getProxy("foo/bar/baz/shout.C"), "FOO/BAR/BAZ/SHOUT.cc"); } +TEST_F(InterpolateTest, LanguagePreference) { + add("foo/bar/baz/exact.C"); + add("foo/bar/baz/exact.c"); + add("other/random/path.cpp"); + // Proxies for ".H" files are ".C" files, and not ".c files". + EXPECT_EQ(getProxy("foo/bar/baz/exact.H"), "foo/bar/baz/exact.C"); +} + TEST_F(InterpolateTest, Aliasing) { add("foo.cpp", "-faligned-new"); _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits