Skip to content

Commit 024c3d0

Browse files
committed
[clang][Interp][NFC] Refactor Program::getGlobal()
Move the iterator declarations into the if statements and return std::nullopt explicitly.
1 parent 36c8af6 commit 024c3d0

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

clang/lib/AST/Interp/Program.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -108,27 +108,23 @@ Pointer Program::getPtrGlobal(unsigned Idx) const {
108108
}
109109

110110
std::optional<unsigned> Program::getGlobal(const ValueDecl *VD) {
111-
auto It = GlobalIndices.find(VD);
112-
if (It != GlobalIndices.end())
111+
if (auto It = GlobalIndices.find(VD); It != GlobalIndices.end())
113112
return It->second;
114113

115114
// Find any previous declarations which were already evaluated.
116115
std::optional<unsigned> Index;
117-
for (const Decl *P = VD; P; P = P->getPreviousDecl()) {
118-
auto It = GlobalIndices.find(P);
119-
if (It != GlobalIndices.end()) {
116+
for (const Decl *P = VD->getPreviousDecl(); P; P = P->getPreviousDecl()) {
117+
if (auto It = GlobalIndices.find(P); It != GlobalIndices.end()) {
120118
Index = It->second;
121119
break;
122120
}
123121
}
124122

125123
// Map the decl to the existing index.
126-
if (Index) {
124+
if (Index)
127125
GlobalIndices[VD] = *Index;
128-
return std::nullopt;
129-
}
130126

131-
return Index;
127+
return std::nullopt;
132128
}
133129

134130
std::optional<unsigned> Program::getOrCreateGlobal(const ValueDecl *VD,

0 commit comments

Comments
 (0)