[llvm-dev] GraphTraits dereferencing

Tim Shen via llvm-dev llvm-dev at lists.llvm.org
Wed May 24 17:17:58 PDT 2017


On Tue, May 23, 2017 at 7:56 PM Jared Carlson via llvm-dev <
llvm-dev at lists.llvm.org> wrote:

> Hello,
>
> I’m trying to port a project up to 4.0 and I’m seeing the following error:
>
> In file included from
> /Users/jaredcarlson/Projects/llvm-4.0.0.src/include/llvm/ADT/StringRef.h:13:
> /Users/jaredcarlson/Projects/llvm-4.0.0.src/include/llvm/ADT/STLExtras.h:139:13:
> error: no type named 'type' in
> 'std::__1::result_of<std::__1::pointer_to_unary_function<llvm::DSNode *,
> llvm::DSNode &>
>       (llvm::DSNode &)>'
>           ::type value_type;
>           ~~^~~~
> /Users/jaredcarlson/Projects/crab-llvm/dsa-seahorn/include/dsa/DSGraphTraits.h:122:25:
> note: in instantiation of template class
>
> 'llvm::mapped_iterator<llvm::ilist_iterator<llvm::ilist_detail::node_options<llvm::DSNode,
> true, false, void>, false, false>,
> std::__1::pointer_to_unary_function<llvm::DSNode *, llvm::DSNode &> >'
>       requested here
>   static nodes_iterator nodes_begin(DSGraph *G) {
>
> So, it looks to me like in DSGraph, the iterator needs to be dereferenced
> correctly.  Right now the source reads:
>
>  template <> struct GraphTraits<DSGraph*> {
>   typedef DSNode NodeType;
>   typedef DSNode::iterator ChildIteratorType;
>
>   // not sure this is necessary anymore as NodeRef must be a pointer
>   typedef std::pointer_to_unary_function<DSNode *, DSNode&> DerefFun;
>
>   // nodes_iterator/begin/end - Allow iteration over all nodes in the graph
>   typedef mapped_iterator<DSGraph::node_iterator, DerefFun> nodes_iterator;
>
>   static nodes_iterator nodes_begin(DSGraph *G) {
>     return map_iterator( G->node_begin(), DerefFun(dereference) );
>   }
>   static nodes_iterator nodes_end(DSGraph *G) {
>     return map_iterator( G->node_end(), DerefFun(dereference) );
>   }
>
>   static ChildIteratorType child_begin(NodeType *N) { return N->begin(); }
>   static ChildIteratorType child_end(NodeType *N) { return N->end(); }
> };
>
> I”m just unsure as in 4.0, there’s a need for a NodeRef to leverage the
> GraphTraits template which needs to be.a pointer but I don’t think that’s
> all that relevant here and the above code looks consistent with what I’m
> used to…
>

Please refer to include/llvm/ADT/GraphTraits.h for the documentation.

In your case, for nodes, simply change `typedef DSNode NodeType;` to
`typedef DSNode* NodeRef;`

I'm not sure what DSGraph::iterator returns on dereference; but ultimately
you want both ChildIteratorType and nodes_iterator to dereference to a
NodeRef, as documented. You may find llvm::pointer_iterator or
llvm::pointee_iterator helpful.

I'd try to remove DerefFun and the usage of mapped_iterator.


>
> DSGraph::iterator by the way is ilist<DSNode>::iterator, as the graph
> allows walking the nodes….
>
> Any hints, would be much appreciated…. Thanks!
>
>
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170525/fece3ca3/attachment.html>


More information about the llvm-dev mailing list