Author: Kadir Cetinkaya Date: 2019-12-20T11:10:36+01:00 New Revision: c2377eae286bbe616267bef772ee736b030dd007
URL: https://github.com/llvm/llvm-project/commit/c2377eae286bbe616267bef772ee736b030dd007 DIFF: https://github.com/llvm/llvm-project/commit/c2377eae286bbe616267bef772ee736b030dd007.diff LOG: [clang][Tooling] Prefer -x over -std when interpolating Summary: 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! Reviewers: sammccall Subscribers: ilya-biryukov, usaxena95, cfe-commits, sammccall Tags: #clang Differential Revision: https://reviews.llvm.org/D71727 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 59b66abe65e9..2cc819a498c6 100644 --- a/clang/lib/Tooling/InterpolatingCompilationDatabase.cpp +++ b/clang/lib/Tooling/InterpolatingCompilationDatabase.cpp @@ -191,7 +191,8 @@ struct TransferableCommand { 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. diff --git a/clang/unittests/Tooling/CompilationDatabaseTest.cpp b/clang/unittests/Tooling/CompilationDatabaseTest.cpp index 91685c0d0c73..56ebadc5eae2 100644 --- a/clang/unittests/Tooling/CompilationDatabaseTest.cpp +++ b/clang/unittests/Tooling/CompilationDatabaseTest.cpp @@ -749,6 +749,7 @@ TEST_F(InterpolateTest, Language) { 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 @@ TEST_F(InterpolateTest, Language) { 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) { _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits