[llvm-dev] A potential race on StaticList in RegisterManagedStatic

Viacheslav Nikolaev via llvm-dev llvm-dev at lists.llvm.org
Sun Dec 25 22:20:31 PST 2016


Ptr member of ManagedStaticBase is now atomic.
In ManagedStaticBase::RegisterManagedStatic we have such code:

      void *Tmp = Creator();

      Ptr.store(Tmp, std::memory_order_release);
      DeleterFn = Deleter;

      // Add to list of managed statics.
      Next = StaticList;
      StaticList = this;


StaticList is not atomic and not guarded by any fence.
The same applies to the members DeleterFn and Next.

Doesn't it seem reasonable to change the code to

      DeleterFn = Deleter;

      // Add to list of managed statics.
      Next = StaticList;
      StaticList = this;
      Ptr.store(Tmp, std::memory_order_release);
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20161226/addc40f4/attachment.html>


More information about the llvm-dev mailing list