[llvm] r223904 - IR: Move call to dropAllReferences() to MDNode subclasses

Duncan P. N. Exon Smith dexonsmith at apple.com
Wed Dec 10 09:44:40 PST 2014


> On 2014 Dec 10, at 09:06, David Blaikie <dblaikie at gmail.com> wrote:
> 
> 
> 
> On Tue, Dec 9, 2014 at 5:45 PM, Duncan P. N. Exon Smith <dexonsmith at apple.com> wrote:
> Author: dexonsmith
> Date: Tue Dec  9 19:45:04 2014
> New Revision: 223904
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=223904&view=rev
> Log:
> IR: Move call to dropAllReferences() to MDNode subclasses
> 
> Don't call `dropAllReferences()` from `MDNode::~MDNode()`, call it
> directly from `~MDNodeFwdDecl()` and `~GenericMDNode()`.
> 
> What was the problem/how did this change address it? (seems unfortunate to have to duplicate things in subclasses, though I realize it's sometimes necessary - just not obvious to me what necessitates it in this instance)
>  
> 
> Modified:
>     llvm/trunk/include/llvm/IR/Metadata.h
>     llvm/trunk/lib/IR/Metadata.cpp
> 

Huh, that commit message was terse.  This fixed a use-after-free.
`dropAllReferences()` accesses `GenericMDNode::ReplaceableUses`.
    
    void MDNode::dropAllReferences() {
      for (unsigned I = 0, E = NumOperands; I != E; ++I)
        setOperand(I, nullptr);
      if (auto *G = dyn_cast<GenericMDNode>(this))
        if (!G->isResolved()) {
          G->ReplaceableUses->resolveAllUses(/* ResolveUsers */ false);
          G->ReplaceableUses.reset();
        }
    }

> Modified: llvm/trunk/include/llvm/IR/Metadata.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/Metadata.h?rev=223904&r1=223903&r2=223904&view=diff
> ==============================================================================
> --- llvm/trunk/include/llvm/IR/Metadata.h (original)
> +++ llvm/trunk/include/llvm/IR/Metadata.h Tue Dec  9 19:45:04 2014
> @@ -598,7 +598,7 @@ protected:
>    }
> 
>    MDNode(LLVMContext &Context, unsigned ID, ArrayRef<Metadata *> MDs);
> -  ~MDNode() { dropAllReferences(); }
> +  ~MDNode() {}
> 
>    void dropAllReferences();
>    void storeDistinctInContext();
> @@ -766,7 +766,7 @@ class MDNodeFwdDecl : public MDNode, Rep
> 
>    MDNodeFwdDecl(LLVMContext &C, ArrayRef<Metadata *> Vals)
>        : MDNode(C, MDNodeFwdDeclKind, Vals) {}
> -  ~MDNodeFwdDecl() {}
> +  ~MDNodeFwdDecl() { dropAllReferences(); }
> 
>  public:
>    static bool classof(const Metadata *MD) {
> 
> Modified: llvm/trunk/lib/IR/Metadata.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Metadata.cpp?rev=223904&r1=223903&r2=223904&view=diff
> ==============================================================================
> --- llvm/trunk/lib/IR/Metadata.cpp (original)
> +++ llvm/trunk/lib/IR/Metadata.cpp Tue Dec  9 19:45:04 2014
> @@ -428,6 +428,7 @@ GenericMDNode::~GenericMDNode() {
>      pImpl->NonUniquedMDNodes.erase(this);
>    else
>      pImpl->MDNodeSet.erase(this);
> +  dropAllReferences();
>  }
> 
>  void GenericMDNode::resolve() {
> 
> 
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
> 





More information about the llvm-commits mailing list