[PATCH] D71727: [clang][Tooling] Prefer -x over -std when interpolating
Kadir Cetinkaya via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Dec 19 13:42:29 PST 2019
kadircet created this revision.
kadircet added a reviewer: sammccall.
Herald added subscribers: cfe-commits, usaxena95, ilya-biryukov.
Herald added a project: clang.
Currently interpolation logic prefers -std over -x. But the latter is a
more strong signal, so this patch inverts the order and only makes use of -std
if -x didn't exist.
Fixes https://github.com/clangd/clangd/issues/185
Thanks @sammccall for tracking this down!
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D71727
Files:
clang/lib/Tooling/InterpolatingCompilationDatabase.cpp
clang/unittests/Tooling/CompilationDatabaseTest.cpp
Index: clang/unittests/Tooling/CompilationDatabaseTest.cpp
===================================================================
--- clang/unittests/Tooling/CompilationDatabaseTest.cpp
+++ clang/unittests/Tooling/CompilationDatabaseTest.cpp
@@ -749,6 +749,7 @@
add("dir/foo.cpp", "-std=c++17");
add("dir/bar.c", "");
add("dir/baz.cee", "-x c");
+ add("dir/aux.cpp", "-std=c++17 -x objective-c++");
// .h is ambiguous, so we add explicit language flags
EXPECT_EQ(getCommand("foo.h"),
@@ -767,6 +768,9 @@
Entries.erase(path(StringRef("dir/bar.c")));
// Now we transfer across languages, so drop -std too.
EXPECT_EQ(getCommand("foo.c"), "clang -D dir/foo.cpp");
+ // Prefer -x over -std when overriding language.
+ EXPECT_EQ(getCommand("aux.h"),
+ "clang -D dir/aux.cpp -x objective-c++-header -std=c++17");
}
TEST_F(InterpolateTest, Strip) {
Index: clang/lib/Tooling/InterpolatingCompilationDatabase.cpp
===================================================================
--- clang/lib/Tooling/InterpolatingCompilationDatabase.cpp
+++ clang/lib/Tooling/InterpolatingCompilationDatabase.cpp
@@ -191,7 +191,8 @@
OldArgs.data() + OldPos, OldArgs.data() + Pos);
}
- if (Std != LangStandard::lang_unspecified) // -std take precedence over -x
+ // Make use of -std iff -x was missing.
+ if (Type == types::TY_INVALID && Std != LangStandard::lang_unspecified)
Type = toType(LangStandard::getLangStandardForKind(Std).getLanguage());
Type = foldType(*Type);
// The contract is to store None instead of TY_INVALID.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D71727.234779.patch
Type: text/x-patch
Size: 1608 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20191219/dd7199b1/attachment.bin>
More information about the cfe-commits
mailing list