[llvm] r255258 - Avoid undefined behavior when vector is empty.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 10 08:35:06 PST 2015


Author: rafael
Date: Thu Dec 10 10:35:06 2015
New Revision: 255258

URL: http://llvm.org/viewvc/llvm-project?rev=255258&view=rev
Log:
Avoid undefined behavior when vector is empty.

Found by ubsan.

Modified:
    llvm/trunk/include/llvm/ADT/SetVector.h
    llvm/trunk/lib/Linker/LinkModules.cpp

Modified: llvm/trunk/include/llvm/ADT/SetVector.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/SetVector.h?rev=255258&r1=255257&r2=255258&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/SetVector.h (original)
+++ llvm/trunk/include/llvm/ADT/SetVector.h Thu Dec 10 10:35:06 2015
@@ -58,6 +58,8 @@ public:
     insert(Start, End);
   }
 
+  ArrayRef<T> getArrayRef() const { return vector_; }
+
   /// \brief Determine if the SetVector is empty or not.
   bool empty() const {
     return vector_.empty();

Modified: llvm/trunk/lib/Linker/LinkModules.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Linker/LinkModules.cpp?rev=255258&r1=255257&r2=255258&view=diff
==============================================================================
--- llvm/trunk/lib/Linker/LinkModules.cpp (original)
+++ llvm/trunk/lib/Linker/LinkModules.cpp Thu Dec 10 10:35:06 2015
@@ -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);
                  }))




More information about the llvm-commits mailing list