Skip to content

[CLANGD] [NFC] Fix proposed by static analyzer. #140116

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 16, 2025

Conversation

zahiraam
Copy link
Contributor

This fixes an issue reported by the sanitizer with the following error message:
copy_constructor_call: IndexOpts is passed by value as a parameter to clang::index::IndexingOptions::IndexingOptions instead of being moved.

@llvmbot
Copy link
Member

llvmbot commented May 15, 2025

@llvm/pr-subscribers-clang-tools-extra

@llvm/pr-subscribers-clangd

Author: Zahira Ammarguellat (zahiraam)

Changes

This fixes an issue reported by the sanitizer with the following error message:
copy_constructor_call: IndexOpts is passed by value as a parameter to clang::index::IndexingOptions::IndexingOptions instead of being moved.


Full diff: https://github.com/llvm/llvm-project/pull/140116.diff

1 Files Affected:

  • (modified) clang-tools-extra/clangd/index/FileIndex.cpp (+2-1)
diff --git a/clang-tools-extra/clangd/index/FileIndex.cpp b/clang-tools-extra/clangd/index/FileIndex.cpp
index 0fe069783d64f..c49de377d54ca 100644
--- a/clang-tools-extra/clangd/index/FileIndex.cpp
+++ b/clang-tools-extra/clangd/index/FileIndex.cpp
@@ -79,7 +79,8 @@ SlabTuple indexSymbols(ASTContext &AST, Preprocessor &PP,
 
   SymbolCollector Collector(std::move(CollectorOpts));
   Collector.setPreprocessor(PP);
-  index::indexTopLevelDecls(AST, PP, DeclsToIndex, Collector, IndexOpts);
+  index::indexTopLevelDecls(AST, PP, DeclsToIndex, Collector,
+                            std::move(IndexOpts));
   if (MacroRefsToIndex)
     Collector.handleMacros(*MacroRefsToIndex);
 

@zahiraam zahiraam changed the title [CLANGD] Fix proposed by sanitizer. [CLANGD] [NFC] Fix proposed by sanitizer. May 15, 2025
Copy link
Contributor

@nicovank nicovank left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

AFAICT in this case this won't make an immediate performance difference since fields in this struct are primitives, but may in the future if the struct changes. This probably won't trigger performance-move-const-arg because of the std::function field where IIRC copying can be expensive in some cases when capturing variables.

Copy link
Contributor

@carlosgalvezp carlosgalvezp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

In the future, please provide more details about exactly which tool you are using, which you call "sanitizer". For example, what is the name of the tool?

"sanitizers" are tools to detect issues at runtime; here you are using a static analyzer.

@zahiraam zahiraam changed the title [CLANGD] [NFC] Fix proposed by sanitizer. [CLANGD] [NFC] Fix proposed by static analyzer. May 16, 2025
@zahiraam zahiraam merged commit 38e0f98 into llvm:main May 16, 2025
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants