[llvm] r243976 - Linker: Fix ASan failure from r243961

Duncan P. N. Exon Smith dexonsmith at apple.com
Tue Aug 4 06:23:31 PDT 2015


Author: dexonsmith
Date: Tue Aug  4 08:23:30 2015
New Revision: 243976

URL: http://llvm.org/viewvc/llvm-project?rev=243976&view=rev
Log:
Linker: Fix ASan failure from r243961

r243883 and r243961 made a use-after-free far more likely:
http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-fast/builds/6041/steps/check-llvm%20asan/logs/stdio

Unresolved nodes get inserted into the `Cycles` array.  If they later
get resolved through RAUW, we need to update the reference.  It's
interesting that this never hit before (maybe an asan-ified clang
bootstrap with `-flto -g` would have hit it, but I admit I haven't tried
anything quite that crazy).

Modified:
    llvm/trunk/lib/Transforms/Utils/ValueMapper.cpp

Modified: llvm/trunk/lib/Transforms/Utils/ValueMapper.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/ValueMapper.cpp?rev=243976&r1=243975&r2=243976&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/ValueMapper.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/ValueMapper.cpp Tue Aug  4 08:23:30 2015
@@ -156,12 +156,13 @@ static Metadata *mapToSelf(ValueToValueM
 }
 
 static Metadata *MapMetadataImpl(const Metadata *MD,
-                                 SmallVectorImpl<MDNode *> &Cycles,
+                                 SmallVectorImpl<TrackingMDNodeRef> &Cycles,
                                  ValueToValueMapTy &VM, RemapFlags Flags,
                                  ValueMapTypeRemapper *TypeMapper,
                                  ValueMaterializer *Materializer);
 
-static Metadata *mapMetadataOp(Metadata *Op, SmallVectorImpl<MDNode *> &Cycles,
+static Metadata *mapMetadataOp(Metadata *Op,
+                               SmallVectorImpl<TrackingMDNodeRef> &Cycles,
                                ValueToValueMapTy &VM, RemapFlags Flags,
                                ValueMapTypeRemapper *TypeMapper,
                                ValueMaterializer *Materializer) {
@@ -189,8 +190,9 @@ static Metadata *mapMetadataOp(Metadata
 ///
 /// \pre \c NewNode is a clone of \c OldNode.
 static bool remap(const MDNode *OldNode, MDNode *NewNode,
-                  SmallVectorImpl<MDNode *> &Cycles, ValueToValueMapTy &VM,
-                  RemapFlags Flags, ValueMapTypeRemapper *TypeMapper,
+                  SmallVectorImpl<TrackingMDNodeRef> &Cycles,
+                  ValueToValueMapTy &VM, RemapFlags Flags,
+                  ValueMapTypeRemapper *TypeMapper,
                   ValueMaterializer *Materializer) {
   assert(OldNode->getNumOperands() == NewNode->getNumOperands() &&
          "Expected nodes to match");
@@ -223,7 +225,7 @@ static bool remap(const MDNode *OldNode,
 /// place; effectively, they're moved from one graph to another.  Otherwise,
 /// they're cloned/duplicated, and the new copy's operands are remapped.
 static Metadata *mapDistinctNode(const MDNode *Node,
-                                 SmallVectorImpl<MDNode *> &Cycles,
+                                 SmallVectorImpl<TrackingMDNodeRef> &Cycles,
                                  ValueToValueMapTy &VM, RemapFlags Flags,
                                  ValueMapTypeRemapper *TypeMapper,
                                  ValueMaterializer *Materializer) {
@@ -241,7 +243,7 @@ static Metadata *mapDistinctNode(const M
     for (Metadata *Op : NewMD->operands())
       if (auto *Node = dyn_cast_or_null<MDNode>(Op))
         if (!Node->isResolved())
-          Cycles.push_back(Node);
+          Cycles.emplace_back(Node);
 
   return NewMD;
 }
@@ -250,7 +252,7 @@ static Metadata *mapDistinctNode(const M
 ///
 /// Uniqued nodes may not need to be recreated (they may map to themselves).
 static Metadata *mapUniquedNode(const MDNode *Node,
-                                SmallVectorImpl<MDNode *> &Cycles,
+                                SmallVectorImpl<TrackingMDNodeRef> &Cycles,
                                 ValueToValueMapTy &VM, RemapFlags Flags,
                                 ValueMapTypeRemapper *TypeMapper,
                                 ValueMaterializer *Materializer) {
@@ -270,7 +272,7 @@ static Metadata *mapUniquedNode(const MD
 }
 
 static Metadata *MapMetadataImpl(const Metadata *MD,
-                                 SmallVectorImpl<MDNode *> &Cycles,
+                                 SmallVectorImpl<TrackingMDNodeRef> &Cycles,
                                  ValueToValueMapTy &VM, RemapFlags Flags,
                                  ValueMapTypeRemapper *TypeMapper,
                                  ValueMaterializer *Materializer) {
@@ -323,7 +325,7 @@ static Metadata *MapMetadataImpl(const M
 Metadata *llvm::MapMetadata(const Metadata *MD, ValueToValueMapTy &VM,
                             RemapFlags Flags, ValueMapTypeRemapper *TypeMapper,
                             ValueMaterializer *Materializer) {
-  SmallVector<MDNode *, 8> Cycles;
+  SmallVector<TrackingMDNodeRef, 8> Cycles;
   Metadata *NewMD =
       MapMetadataImpl(MD, Cycles, VM, Flags, TypeMapper, Materializer);
 





More information about the llvm-commits mailing list