Skip to content

Commit 6566ffd

Browse files
kevinfreiKevin Frei
and
Kevin Frei
authored
Clean up the GSym error aggregation code, and pass the aggregator by reference (#89688)
There was a problem with `llvm-gsymutil`s error aggregation code not properly collecting aggregate errors. The was that the output aggregator collecting errors from other threads wasn't being passed by reference, so it was merging them into a copy of the app-wide output aggregator. While I was at it, I added a better comment above the "Merge" code and made it a bit more efficient, after learning more details about `emplace` vs. `insert` or `operator[]` on `std::map`'s. Co-authored-by: Kevin Frei <[email protected]>
1 parent 1cb3371 commit 6566ffd

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

llvm/include/llvm/DebugInfo/GSYM/OutputAggregator.h

+4-5
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,12 @@ class OutputAggregator {
5757
}
5858

5959
// For multi-threaded usage, we can collect stuff in another aggregator,
60-
// then merge it in here
60+
// then merge it in here. Note that this is *not* thread safe. It is up to
61+
// the caller to ensure that this is only called from one thread at a time.
6162
void Merge(const OutputAggregator &other) {
6263
for (auto &&[name, count] : other.Aggregation) {
63-
auto it = Aggregation.find(name);
64-
if (it == Aggregation.end())
65-
Aggregation.emplace(name, count);
66-
else
64+
auto [it, inserted] = Aggregation.emplace(name, count);
65+
if (!inserted)
6766
it->second += count;
6867
}
6968
}

llvm/lib/DebugInfo/GSYM/DwarfTransformer.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ Error DwarfTransformer::convert(uint32_t NumThreads, OutputAggregator &Out) {
612612
DWARFDie Die = getDie(*CU);
613613
if (Die) {
614614
CUInfo CUI(DICtx, dyn_cast<DWARFCompileUnit>(CU.get()));
615-
pool.async([this, CUI, &LogMutex, Out, Die]() mutable {
615+
pool.async([this, CUI, &LogMutex, &Out, Die]() mutable {
616616
std::string storage;
617617
raw_string_ostream StrStream(storage);
618618
OutputAggregator ThreadOut(Out.GetOS() ? &StrStream : nullptr);

0 commit comments

Comments
 (0)