[lld] r226883 - Make access to LinkingContext::getNode safe.

Jean-Daniel Dupas dev at xenonium.com
Fri Jan 23 08:17:31 PST 2015


Does it not reveal a race condition here ? 
An action preformed in background by the thread pool should not affect the behavior of the current thread.

> Le 23 janv. 2015 à 01:09, Rui Ueyama <ruiu at google.com> a écrit :
> 
> Author: ruiu
> Date: Thu Jan 22 18:09:05 2015
> New Revision: 226883
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=226883&view=rev
> Log:
> Make access to LinkingContext::getNode safe.
> 
> Modified:
>    lld/trunk/lib/Driver/Driver.cpp
> 
> Modified: lld/trunk/lib/Driver/Driver.cpp
> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/Driver.cpp?rev=226883&r1=226882&r2=226883&view=diff
> ==============================================================================
> --- lld/trunk/lib/Driver/Driver.cpp (original)
> +++ lld/trunk/lib/Driver/Driver.cpp Thu Jan 22 18:09:05 2015
> @@ -77,8 +77,11 @@ bool Driver::link(LinkingContext &contex
>   if (context.getNodes().empty())
>     return false;
> 
> -  for (std::unique_ptr<Node> &ie : context.getNodes())
> -    if (FileNode *node = dyn_cast<FileNode>(ie.get()))
> +  // File::parse may add items to the node list which may invalidate
> +  // existing iterators. Avoid using iterator to access elements.
> +  std::vector<std::unique_ptr<Node>> &nodes = context.getNodes();
> +  for (size_t i = 0; i < nodes.size(); ++i)
> +    if (FileNode *node = dyn_cast<FileNode>(nodes[i].get()))
>       context.getTaskGroup().spawn([node] { node->getFile()->parse(); });
> 
>   std::vector<std::unique_ptr<File>> internalFiles;
> 
> 
> _______________________________________________
> 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