From: Rafael Espindola Date: Thu, 10 Dec 2015 16:35:06 +0000 (+0000) Subject: Avoid undefined behavior when vector is empty. X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=4d1332c4e7d3c428f5c5a9b08f02ea70deeac283;p=oota-llvm.git Avoid undefined behavior when vector is empty. Found by ubsan. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@255258 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/ADT/SetVector.h b/include/llvm/ADT/SetVector.h index 3ab202d8d71..bc563570c20 100644 --- a/include/llvm/ADT/SetVector.h +++ b/include/llvm/ADT/SetVector.h @@ -58,6 +58,8 @@ public: insert(Start, End); } + ArrayRef getArrayRef() const { return vector_; } + /// \brief Determine if the SetVector is empty or not. bool empty() const { return vector_.empty(); diff --git a/lib/Linker/LinkModules.cpp b/lib/Linker/LinkModules.cpp index 3d3454f3f7f..a596697e8f5 100644 --- a/lib/Linker/LinkModules.cpp +++ b/lib/Linker/LinkModules.cpp @@ -772,8 +772,7 @@ bool ModuleLinker::run() { Internalize.insert(GV->getName()); } - if (Mover.move(SrcM, - makeArrayRef(&*ValuesToLink.begin(), ValuesToLink.size()), + if (Mover.move(SrcM, ValuesToLink.getArrayRef(), [this](GlobalValue &GV, IRMover::ValueAdder Add) { addLazyFor(GV, Add); }))