https://github.com/HighCommander4 created https://github.com/llvm/llvm-project/pull/156593
SawInput() is intended to be called for every argument after a `--`, but it was mistakenly being called for the `--` itself. Partially fixes https://github.com/clangd/clangd/issues/1850 >From fa70f4e7224055953e17971be7c4d47b1167c569 Mon Sep 17 00:00:00 2001 From: Nathan Ridge <zeratul...@hotmail.com> Date: Wed, 3 Sep 2025 02:37:53 -0400 Subject: [PATCH] [clangd] Fix off-by-one error in CommandMangler SawInput() is intended to be called for every argument after a `--`, but it was mistakenly being called for the `--` itself. Partially fixes https://github.com/clangd/clangd/issues/1850 --- clang-tools-extra/clangd/CompileCommands.cpp | 3 ++- .../clangd/unittests/CompileCommandsTests.cpp | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/clang-tools-extra/clangd/CompileCommands.cpp b/clang-tools-extra/clangd/CompileCommands.cpp index 80391fe8cce25..c9da98e96ccfb 100644 --- a/clang-tools-extra/clangd/CompileCommands.cpp +++ b/clang-tools-extra/clangd/CompileCommands.cpp @@ -270,7 +270,8 @@ void CommandMangler::operator()(tooling::CompileCommand &Command, if (auto *DashDash = ArgList.getLastArgNoClaim(driver::options::OPT__DASH_DASH)) { auto DashDashIndex = DashDash->getIndex() + 1; // +1 accounts for Cmd[0] - for (unsigned I = DashDashIndex; I < Cmd.size(); ++I) + // Another +1 so we don't treat the `--` itself as an input. + for (unsigned I = DashDashIndex + 1; I < Cmd.size(); ++I) SawInput(Cmd[I]); Cmd.resize(DashDashIndex); } diff --git a/clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp b/clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp index 2ce2975bd962b..44bbc31b463d7 100644 --- a/clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp +++ b/clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp @@ -526,6 +526,16 @@ TEST(CommandMangler, RespectsOriginalSysroot) { Not(HasSubstr(testPath("fake/sysroot")))); } } + +TEST(CommandMangler, StdLatestFlag) { + const auto Mangler = CommandMangler::forTests(); + tooling::CompileCommand Cmd; + Cmd.CommandLine = {"clang-cl", "-std:c++latest", "--", "/Users/foo.cc"}; + Mangler(Cmd, "/Users/foo.cc"); + // Check that the -std:c++latest flag is not dropped + EXPECT_THAT(llvm::join(Cmd.CommandLine, " "), HasSubstr("-std:c++latest")); +} + } // namespace } // namespace clangd } // namespace clang _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits