[graph] Problem with vertex initialization in boost::add_vertex()

I have graph as follows: struct cfg_node { iCode *ic; operand_map_t operands; std::set<var_t> alive; std::set<var_t> dying; }; typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::bidirectionalS, cfg_node> cfg_t; And a fragment of code: wassertl (!boost::num_vertices(cfg), "CFG non-empty before creation."); for (ic = start_ic, i = 0, j = 0; ic; ic = ic->next, i++) { boost::add_vertex(cfg); wassertl (cfg[i].alive.empty(), "Alive set non-empty upon creation."); Nothing inside the loop add or deletes vertices or changes the alive members. The code works fine on Linux, but I got bug reports from Windows users. For them the assertion in the loop triggers (and an attempt to insert something into alive later segfaults). So I have two questions: What could be the cause of this problem? Has it been encountered before? Is the approach of using cfg[i] to get the vertex still correct? I've used this for some time, but I can't find it in current boost documentation. Philipp

On Thu, 5 Apr 2012, Philipp Klaus Krause wrote:
I have graph as follows:
struct cfg_node { iCode *ic; operand_map_t operands; std::set<var_t> alive; std::set<var_t> dying; };
typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::bidirectionalS, cfg_node> cfg_t;
And a fragment of code:
wassertl (!boost::num_vertices(cfg), "CFG non-empty before creation."); for (ic = start_ic, i = 0, j = 0; ic; ic = ic->next, i++) { boost::add_vertex(cfg); wassertl (cfg[i].alive.empty(), "Alive set non-empty upon creation.");
Nothing inside the loop add or deletes vertices or changes the alive members.
The code works fine on Linux, but I got bug reports from Windows users. For them the assertion in the loop triggers (and an attempt to insert something into alive later segfaults).
Have you tried Valgrind on Linux?
So I have two questions:
What could be the cause of this problem? Has it been encountered before?
Are you sure ic is initialized correctly (pointing to other vertices in the graph)? Otherwise, I don't see a reason why your code wouldn't work.
Is the approach of using cfg[i] to get the vertex still correct? I've used this for some time, but I can't find it in current boost documentation.
Yes -- see <URL:http://www.boost.org/doc/libs/1_49_0/libs/graph/doc/bundles.html>. -- Jeremiah Willcock

On 05.04.2012 15:16, Jeremiah Willcock wrote:
On Thu, 5 Apr 2012, Philipp Klaus Krause wrote:
I have graph as follows:
struct cfg_node { iCode *ic; operand_map_t operands; std::set<var_t> alive; std::set<var_t> dying; };
typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::bidirectionalS, cfg_node> cfg_t;
And a fragment of code:
wassertl (!boost::num_vertices(cfg), "CFG non-empty before creation."); for (ic = start_ic, i = 0, j = 0; ic; ic = ic->next, i++) { boost::add_vertex(cfg); wassertl (cfg[i].alive.empty(), "Alive set non-empty upon creation.");
Nothing inside the loop add or deletes vertices or changes the alive members.
The code works fine on Linux, but I got bug reports from Windows users. For them the assertion in the loop triggers (and an attempt to insert something into alive later segfaults).
Have you tried Valgrind on Linux?
So I have two questions:
What could be the cause of this problem? Has it been encountered before?
Are you sure ic is initialized correctly (pointing to other vertices in the graph)? Otherwise, I don't see a reason why your code wouldn't work.
To me it seems as if the default constructor of alive is not called upon add_vertex(), resulting in alive being uninitialized memory (same for dying). Philipp P.S.: var_t is a typedef for short.

On Thu, 5 Apr 2012, Philipp Klaus Krause wrote:
On 05.04.2012 15:16, Jeremiah Willcock wrote:
On Thu, 5 Apr 2012, Philipp Klaus Krause wrote:
I have graph as follows:
struct cfg_node { iCode *ic; operand_map_t operands; std::set<var_t> alive; std::set<var_t> dying; };
typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::bidirectionalS, cfg_node> cfg_t;
And a fragment of code:
wassertl (!boost::num_vertices(cfg), "CFG non-empty before creation."); for (ic = start_ic, i = 0, j = 0; ic; ic = ic->next, i++) { boost::add_vertex(cfg); wassertl (cfg[i].alive.empty(), "Alive set non-empty upon creation.");
Nothing inside the loop add or deletes vertices or changes the alive members.
The code works fine on Linux, but I got bug reports from Windows users. For them the assertion in the loop triggers (and an attempt to insert something into alive later segfaults).
Have you tried Valgrind on Linux?
So I have two questions:
What could be the cause of this problem? Has it been encountered before?
Are you sure ic is initialized correctly (pointing to other vertices in the graph)? Otherwise, I don't see a reason why your code wouldn't work.
To me it seems as if the default constructor of alive is not called upon add_vertex(), resulting in alive being uninitialized memory (same for dying).
Could you please add a hand-written default constructor that prints something out to be sure of that? -- Jeremiah Willcock

On 05.04.2012 16:06, Jeremiah Willcock wrote:
To me it seems as if the default constructor of alive is not called upon add_vertex(), resulting in alive being uninitialized memory (same for dying).
Could you please add a hand-written default constructor that prints something out to be sure of that?
Is there an easy way to do this? I'm not a C++ expert. alive is an std::set, so I would have to edit my STL headers? Philipp

On Fri, 6 Apr 2012, Philipp Klaus Krause wrote:
On 05.04.2012 16:06, Jeremiah Willcock wrote:
To me it seems as if the default constructor of alive is not called upon add_vertex(), resulting in alive being uninitialized memory (same for dying).
Could you please add a hand-written default constructor that prints something out to be sure of that?
Is there an easy way to do this? I'm not a C++ expert. alive is an std::set, so I would have to edit my STL headers?
I mean just putting in a default constructor for your whole class, not necessarily each member of it. -- Jeremiah Willcock
participants (2)
-
Jeremiah Willcock
-
Philipp Klaus Krause