llvm.org GIT mirror llvm / 6815ff0
Avoid undefined behaviour if somehow NUM_GRAPHS equals 2^32 (or 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 Duncan Sands 9 years ago
1 changed file(s) with 7 addition(s) and 11 deletion(s). Raw diff Collapse all Expand all
248248 // create graphs for which every node has a self-edge.
249249 #define NUM_NODES 4
250250 #define NUM_GRAPHS (NUM_NODES * (NUM_NODES - 1))
251
252 /// GraphDescriptor - Enumerate all graphs using NUM_GRAPHS bits.
253 unsigned GraphDescriptor = 0;
254 assert(NUM_GRAPHS <= sizeof(unsigned) * CHAR_BIT && "Too many graphs!");
255
256 do {
257 typedef Graph GT;
258
251 typedef Graph GT;
252
253 /// Enumerate all graphs using NUM_GRAPHS bits.
254 assert(NUM_GRAPHS < sizeof(unsigned) * CHAR_BIT && "Too many graphs!");
255 for (unsigned GraphDescriptor = 0; GraphDescriptor < (1U << NUM_GRAPHS);
256 ++GraphDescriptor) {
259257 GT G;
260258
261259 // Add edges as specified by the descriptor.
341339 // Finally, check that the nodes in some SCC are exactly those that are
342340 // reachable from the initial node.
343341 EXPECT_EQ(NodesInSomeSCC, G.NodesReachableFrom(0));
344
345 ++GraphDescriptor;
346 } while (GraphDescriptor && GraphDescriptor < (1U << NUM_GRAPHS));
342 }
347343 }
348344
349345 }