Skip to content

Commit

Permalink
Avoid undefined behaviour if somehow NUM_GRAPHS equals 2^32 (or
Browse files Browse the repository at this point in the history
whatever the size of unsigned is), though this can't actually
occur for any integer value of NUM_NODES.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@136460 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
CunningBaldrick committed Jul 29, 2011
1 parent 3c036e5 commit 6815ff0
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions unittests/ADT/SCCIteratorTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,14 +249,12 @@ TEST(SCCIteratorTest, AllSmallGraphs) {
// create graphs for which every node has a self-edge.
#define NUM_NODES 4
#define NUM_GRAPHS (NUM_NODES * (NUM_NODES - 1))
typedef Graph<NUM_NODES> GT;

/// GraphDescriptor - Enumerate all graphs using NUM_GRAPHS bits.
unsigned GraphDescriptor = 0;
assert(NUM_GRAPHS <= sizeof(unsigned) * CHAR_BIT && "Too many graphs!");

do {
typedef Graph<NUM_NODES> GT;

/// Enumerate all graphs using NUM_GRAPHS bits.
assert(NUM_GRAPHS < sizeof(unsigned) * CHAR_BIT && "Too many graphs!");
for (unsigned GraphDescriptor = 0; GraphDescriptor < (1U << NUM_GRAPHS);
++GraphDescriptor) {
GT G;

// Add edges as specified by the descriptor.
Expand Down Expand Up @@ -342,9 +340,7 @@ TEST(SCCIteratorTest, AllSmallGraphs) {
// Finally, check that the nodes in some SCC are exactly those that are
// reachable from the initial node.
EXPECT_EQ(NodesInSomeSCC, G.NodesReachableFrom(0));

++GraphDescriptor;
} while (GraphDescriptor && GraphDescriptor < (1U << NUM_GRAPHS));
}
}

}

0 comments on commit 6815ff0

Please sign in to comment.