Author: Timm Bäder Date: 2024-04-22T15:28:00+02:00 New Revision: 024c3d0c079fd9297725c35082316f2ca29c9526
URL: https://github.com/llvm/llvm-project/commit/024c3d0c079fd9297725c35082316f2ca29c9526 DIFF: https://github.com/llvm/llvm-project/commit/024c3d0c079fd9297725c35082316f2ca29c9526.diff LOG: [clang][Interp][NFC] Refactor Program::getGlobal() Move the iterator declarations into the if statements and return std::nullopt explicitly. Added: Modified: clang/lib/AST/Interp/Program.cpp Removed: ################################################################################ diff --git a/clang/lib/AST/Interp/Program.cpp b/clang/lib/AST/Interp/Program.cpp index 2c8c6781b34833..7bf842f1a9404b 100644 --- a/clang/lib/AST/Interp/Program.cpp +++ b/clang/lib/AST/Interp/Program.cpp @@ -108,27 +108,23 @@ Pointer Program::getPtrGlobal(unsigned Idx) const { } std::optional<unsigned> Program::getGlobal(const ValueDecl *VD) { - auto It = GlobalIndices.find(VD); - if (It != GlobalIndices.end()) + if (auto It = GlobalIndices.find(VD); It != GlobalIndices.end()) return It->second; // Find any previous declarations which were already evaluated. std::optional<unsigned> Index; - for (const Decl *P = VD; P; P = P->getPreviousDecl()) { - auto It = GlobalIndices.find(P); - if (It != GlobalIndices.end()) { + for (const Decl *P = VD->getPreviousDecl(); P; P = P->getPreviousDecl()) { + if (auto It = GlobalIndices.find(P); It != GlobalIndices.end()) { Index = It->second; break; } } // Map the decl to the existing index. - if (Index) { + if (Index) GlobalIndices[VD] = *Index; - return std::nullopt; - } - return Index; + return std::nullopt; } std::optional<unsigned> Program::getOrCreateGlobal(const ValueDecl *VD, _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits