From 4d1332c4e7d3c428f5c5a9b08f02ea70deeac283 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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@255258 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/ADT/SetVector.h | 2 ++ lib/Linker/LinkModules.cpp | 3 +-- 2 files changed, 3 insertions(+), 2 deletions(-) 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); })) -- 2.34.1