Skip to content

Commit 81925d1

Browse files
r-barnesfacebook-github-bot
authored andcommitted
Fix shadowed variable in gloo/allgatherv.cc
Summary: Our upcoming compiler upgrade will require us not to have shadowed variables. Such variables have a _high_ bug rate and reduce readability, so we would like to avoid them even if the compiler was not forcing us to do so. This codemod attempts to fix an instance of a shadowed variable. Please review with care: if it's failed the result will be a silent bug. **What's a shadowed variable?** Shadowed variables are variables in an inner scope with the same name as another variable in an outer scope. Having the same name for both variables might be semantically correct, but it can make the code confusing to read! It can also hide subtle bugs. This diff fixes such an issue by renaming the variable. - If you approve of this diff, please use the "Accept & Ship" button :-) Reviewed By: dmm-fb Differential Revision: D59008860 fbshipit-source-id: 5966c74486b9f48092eba840a8801db60a4ac326
1 parent c82c8b9 commit 81925d1

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

gloo/allgatherv.cc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,14 @@ void AllgathervOptions::setOutput(
5858

5959
void AllgathervOptions::setOutput(
6060
void* ptr,
61-
std::vector<size_t> elements,
62-
size_t elementSize) {
61+
std::vector<size_t> elements_2,
62+
size_t elementSize_2) {
6363
const auto totalElements =
64-
std::accumulate(elements.begin(), elements.end(), size_t(0));
65-
setElementSize(elementSize);
66-
GLOO_ENFORCE_EQ(elements.size(), context->size);
67-
this->elements = std::move(elements);
68-
this->out = context->createUnboundBuffer(ptr, totalElements * elementSize);
64+
std::accumulate(elements_2.begin(), elements_2.end(), size_t(0));
65+
setElementSize(elementSize_2);
66+
GLOO_ENFORCE_EQ(elements_2.size(), context->size);
67+
this->elements = std::move(elements_2);
68+
this->out = context->createUnboundBuffer(ptr, totalElements * elementSize_2);
6969
}
7070

7171
void allgatherv(AllgathervOptions& opts) {

gloo/gatherv.cc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,15 @@ void GathervOptions::setOutput(
5959

6060
void GathervOptions::setOutput(
6161
void* ptr,
62-
std::vector<size_t> elementsPerRank,
63-
size_t elementSize) {
62+
std::vector<size_t> elementsPerRank_2,
63+
size_t elementSize_2) {
6464
const auto totalElements =
6565
std::accumulate(
66-
elementsPerRank.begin(), elementsPerRank.end(), size_t(0));
67-
this->setElementSize(elementSize);
68-
GLOO_ENFORCE_EQ(elementsPerRank.size(), context->size);
69-
this->elementsPerRank = std::move(elementsPerRank);
70-
this->out = context->createUnboundBuffer(ptr, totalElements * elementSize);
66+
elementsPerRank_2.begin(), elementsPerRank_2.end(), size_t(0));
67+
this->setElementSize(elementSize_2);
68+
GLOO_ENFORCE_EQ(elementsPerRank_2.size(), context->size);
69+
this->elementsPerRank = std::move(elementsPerRank_2);
70+
this->out = context->createUnboundBuffer(ptr, totalElements * elementSize_2);
7171
}
7272

7373
void gatherv(GathervOptions& opts) {

0 commit comments

Comments
 (0)