Skip to content

Commit 23ace26

Browse files
committed
[clang(d)] Include/Exclude CLDXC options properly
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
1 parent 1d1a98e commit 23ace26

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

clang-tools-extra/clangd/CompileCommands.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,10 +220,13 @@ void CommandMangler::adjust(std::vector<std::string> &Cmd,
220220
ArgList = OptTable.ParseArgs(
221221
llvm::makeArrayRef(OriginalArgs).drop_front(), IgnoredCount, IgnoredCount,
222222
/*FlagsToInclude=*/
223-
IsCLMode ? (driver::options::CLOption | driver::options::CoreOption)
223+
IsCLMode ? (driver::options::CLOption | driver::options::CoreOption |
224+
driver::options::CLDXCOption)
224225
: /*everything*/ 0,
225226
/*FlagsToExclude=*/driver::options::NoDriverOption |
226-
(IsCLMode ? 0 : driver::options::CLOption));
227+
(IsCLMode
228+
? 0
229+
: (driver::options::CLOption | driver::options::CLDXCOption)));
227230

228231
llvm::SmallVector<unsigned, 1> IndicesToDrop;
229232
// Having multiple architecture options (e.g. when building fat binaries)

clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,19 @@ TEST(CommandMangler, EmptyArgs) {
415415
// Make sure we don't crash.
416416
Mangler.adjust(Args, "foo.cc");
417417
}
418+
419+
TEST(CommandMangler, PathsAsPositional) {
420+
const auto Mangler = CommandMangler::forTests();
421+
std::vector<std::string> Args = {
422+
"clang",
423+
"--driver-mode=cl",
424+
"-I",
425+
"foo",
426+
};
427+
// Make sure we don't crash.
428+
Mangler.adjust(Args, "a.cc");
429+
EXPECT_THAT(Args, Contains("foo"));
430+
}
418431
} // namespace
419432
} // namespace clangd
420433
} // namespace clang

clang/lib/Tooling/InterpolatingCompilationDatabase.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,8 @@ struct TransferableCommand {
165165
const unsigned OldPos = Pos;
166166
std::unique_ptr<llvm::opt::Arg> Arg(OptTable.ParseOneArg(
167167
ArgList, Pos,
168-
/* Include */ ClangCLMode ? CoreOption | CLOption : 0,
169-
/* Exclude */ ClangCLMode ? 0 : CLOption));
168+
/* Include */ ClangCLMode ? CoreOption | CLOption | CLDXCOption : 0,
169+
/* Exclude */ ClangCLMode ? 0 : CLOption | CLDXCOption));
170170

171171
if (!Arg)
172172
continue;

0 commit comments

Comments
 (0)