Skip to content

[Clang][NFC] Use const auto & to avoid copy #138069

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 1, 2025

Conversation

shafik
Copy link
Collaborator

@shafik shafik commented May 1, 2025

Static analysis flagged this code as causing a copy when we never modify ModName and therefore we can use const auto & and avoid copying.

Static analysis flagged this code as causing a copy when we never modify ModName
and therefore we can use const auto & and avoid copying.
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" clang:modules C++20 modules and Clang Header Modules labels May 1, 2025
@llvmbot
Copy link
Member

llvmbot commented May 1, 2025

@llvm/pr-subscribers-clang

Author: Shafik Yaghmour (shafik)

Changes

Static analysis flagged this code as causing a copy when we never modify ModName and therefore we can use const auto & and avoid copying.


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

1 Files Affected:

  • (modified) clang/lib/Lex/ModuleMap.cpp (+1-1)
diff --git a/clang/lib/Lex/ModuleMap.cpp b/clang/lib/Lex/ModuleMap.cpp
index a1394fd3900b0..74fe55fbe24f2 100644
--- a/clang/lib/Lex/ModuleMap.cpp
+++ b/clang/lib/Lex/ModuleMap.cpp
@@ -1959,7 +1959,7 @@ void ModuleMapLoader::handleExportDecl(const modulemap::ExportDecl &ED) {
 }
 
 void ModuleMapLoader::handleExportAsDecl(const modulemap::ExportAsDecl &EAD) {
-  auto ModName = EAD.Id.front();
+  const auto &ModName = EAD.Id.front();
 
   if (!ActiveModule->ExportAsModule.empty()) {
     if (ActiveModule->ExportAsModule == ModName.first) {

@llvmbot
Copy link
Member

llvmbot commented May 1, 2025

@llvm/pr-subscribers-clang-modules

Author: Shafik Yaghmour (shafik)

Changes

Static analysis flagged this code as causing a copy when we never modify ModName and therefore we can use const auto & and avoid copying.


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

1 Files Affected:

  • (modified) clang/lib/Lex/ModuleMap.cpp (+1-1)
diff --git a/clang/lib/Lex/ModuleMap.cpp b/clang/lib/Lex/ModuleMap.cpp
index a1394fd3900b0..74fe55fbe24f2 100644
--- a/clang/lib/Lex/ModuleMap.cpp
+++ b/clang/lib/Lex/ModuleMap.cpp
@@ -1959,7 +1959,7 @@ void ModuleMapLoader::handleExportDecl(const modulemap::ExportDecl &ED) {
 }
 
 void ModuleMapLoader::handleExportAsDecl(const modulemap::ExportAsDecl &EAD) {
-  auto ModName = EAD.Id.front();
+  const auto &ModName = EAD.Id.front();
 
   if (!ActiveModule->ExportAsModule.empty()) {
     if (ActiveModule->ExportAsModule == ModName.first) {

@shafik shafik merged commit acc40ed into llvm:main May 1, 2025
15 checks passed
@shafik shafik deleted the const_auto_ref_vs_copy_handleExportAsDecl branch May 2, 2025 04:36
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
Static analysis flagged this code as causing a copy when we never modify
ModName and therefore we can use const auto & and avoid copying.
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
Static analysis flagged this code as causing a copy when we never modify
ModName and therefore we can use const auto & and avoid copying.
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
Static analysis flagged this code as causing a copy when we never modify
ModName and therefore we can use const auto & and avoid copying.
GeorgeARM pushed a commit to GeorgeARM/llvm-project that referenced this pull request May 7, 2025
Static analysis flagged this code as causing a copy when we never modify
ModName and therefore we can use const auto & and avoid copying.
Ankur-0429 pushed a commit to Ankur-0429/llvm-project that referenced this pull request May 9, 2025
Static analysis flagged this code as causing a copy when we never modify
ModName and therefore we can use const auto & and avoid copying.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" clang:modules C++20 modules and Clang Header Modules clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants