From f81c7b03a03aee39267cdbce9bdf728892c61262 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Thu, 10 Dec 2015 16:35:06 +0000 Subject: [PATCH] Avoid undefined behavior when vector is empty. Found by ubsan. llvm-svn: 255258 --- llvm/include/llvm/ADT/SetVector.h | 2 ++ llvm/lib/Linker/LinkModules.cpp | 3 +-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/llvm/include/llvm/ADT/SetVector.h b/llvm/include/llvm/ADT/SetVector.h index 3ab202d..bc56357 100644 --- a/llvm/include/llvm/ADT/SetVector.h +++ b/llvm/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/llvm/lib/Linker/LinkModules.cpp b/llvm/lib/Linker/LinkModules.cpp index 3d3454f..a596697 100644 --- a/llvm/lib/Linker/LinkModules.cpp +++ b/llvm/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); })) -- 2.7.4