Author: Nathan Ridge Date: 2025-09-30T02:49:04-04:00 New Revision: ea452c0a020a7ad35bde86c0accabe1c994941aa
URL: https://github.com/llvm/llvm-project/commit/ea452c0a020a7ad35bde86c0accabe1c994941aa DIFF: https://github.com/llvm/llvm-project/commit/ea452c0a020a7ad35bde86c0accabe1c994941aa.diff LOG: [clangd] Fix off-by-one error in CommandMangler (#160029) 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 Added: Modified: clang-tools-extra/clangd/CompileCommands.cpp clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp Removed: ################################################################################ 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..e324404e627c2 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 [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
