Skip to content

Commit

Permalink
[clang(d)] Include/Exclude CLDXC options properly
Browse files Browse the repository at this point in the history
This handles the new CLDXC options that was introduced in
https://reviews.llvm.org/D128462 inside clang-tooling to make sure cl driver
mode is not broken.

Fixes clangd/clangd#1292.

Differential Revision: https://reviews.llvm.org/D133962
  • Loading branch information
kadircet committed Sep 16, 2022
1 parent 1d1a98e commit 23ace26
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
7 changes: 5 additions & 2 deletions clang-tools-extra/clangd/CompileCommands.cpp
Expand Up @@ -220,10 +220,13 @@ void CommandMangler::adjust(std::vector<std::string> &Cmd,
ArgList = OptTable.ParseArgs(
llvm::makeArrayRef(OriginalArgs).drop_front(), IgnoredCount, IgnoredCount,
/*FlagsToInclude=*/
IsCLMode ? (driver::options::CLOption | driver::options::CoreOption)
IsCLMode ? (driver::options::CLOption | driver::options::CoreOption |
driver::options::CLDXCOption)
: /*everything*/ 0,
/*FlagsToExclude=*/driver::options::NoDriverOption |
(IsCLMode ? 0 : driver::options::CLOption));
(IsCLMode
? 0
: (driver::options::CLOption | driver::options::CLDXCOption)));

llvm::SmallVector<unsigned, 1> IndicesToDrop;
// Having multiple architecture options (e.g. when building fat binaries)
Expand Down
13 changes: 13 additions & 0 deletions clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
Expand Up @@ -415,6 +415,19 @@ TEST(CommandMangler, EmptyArgs) {
// Make sure we don't crash.
Mangler.adjust(Args, "foo.cc");
}

TEST(CommandMangler, PathsAsPositional) {
const auto Mangler = CommandMangler::forTests();
std::vector<std::string> Args = {
"clang",
"--driver-mode=cl",
"-I",
"foo",
};
// Make sure we don't crash.
Mangler.adjust(Args, "a.cc");
EXPECT_THAT(Args, Contains("foo"));
}
} // namespace
} // namespace clangd
} // namespace clang
4 changes: 2 additions & 2 deletions clang/lib/Tooling/InterpolatingCompilationDatabase.cpp
Expand Up @@ -165,8 +165,8 @@ struct TransferableCommand {
const unsigned OldPos = Pos;
std::unique_ptr<llvm::opt::Arg> Arg(OptTable.ParseOneArg(
ArgList, Pos,
/* Include */ ClangCLMode ? CoreOption | CLOption : 0,
/* Exclude */ ClangCLMode ? 0 : CLOption));
/* Include */ ClangCLMode ? CoreOption | CLOption | CLDXCOption : 0,
/* Exclude */ ClangCLMode ? 0 : CLOption | CLDXCOption));

if (!Arg)
continue;
Expand Down

0 comments on commit 23ace26

Please sign in to comment.