Skip to content

Conversation

@kazutakahirata
Copy link
Contributor

This patch provides default member initialization for SymInfo, which
in turns allows us to call std::map::try_emplace without the value.

This patch provides default member initialization for SymInfo, which
in turns allows us to call std::map::try_emplace without the value.
@llvmbot
Copy link
Member

llvmbot commented May 21, 2025

@llvm/pr-subscribers-debuginfo

Author: Kazu Hirata (kazutakahirata)

Changes

This patch provides default member initialization for SymInfo, which
in turns allows us to call std::map::try_emplace without the value.


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

1 Files Affected:

  • (modified) llvm/lib/DebugInfo/DWARF/DWARFContext.cpp (+3-3)
diff --git a/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp b/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
index 27aa99ae94fce..6d0a94d8a3367 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
@@ -1902,8 +1902,8 @@ static Error createError(const Twine &Reason, llvm::Error E) {
 /// SymInfo contains information about symbol: it's address
 /// and section index which is -1LL for absolute symbols.
 struct SymInfo {
-  uint64_t Address;
-  uint64_t SectionIndex;
+  uint64_t Address = 0;
+  uint64_t SectionIndex = 0;
 };
 
 /// Returns the address of symbol relocation used against and a section index.
@@ -1921,7 +1921,7 @@ static Expected<SymInfo> getSymbolInfo(const object::ObjectFile &Obj,
   // in the object file
   if (Sym != Obj.symbol_end()) {
     bool New;
-    std::tie(CacheIt, New) = Cache.insert({*Sym, {0, 0}});
+    std::tie(CacheIt, New) = Cache.try_emplace(*Sym);
     if (!New)
       return CacheIt->second;
 

Copy link
Collaborator

@dwblaikie dwblaikie left a comment

Choose a reason for hiding this comment

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

I don't feel strongly that this is an improvement... but if it's good for you, I don't object either.

@kazutakahirata kazutakahirata merged commit 557448e into llvm:main May 21, 2025
13 checks passed
@kazutakahirata kazutakahirata deleted the cleanup_try_emplace_default_llvm_DebugInfo branch May 21, 2025 04:39
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.

3 participants