[llvm-commits] [llvm] r136460 - /llvm/trunk/unittests/ADT/SCCIteratorTest.cpp
Duncan Sands
baldrick at free.fr
Fri Jul 29 00:50:02 PDT 2011
Author: baldrick
Date: Fri Jul 29 02:50:02 2011
New Revision: 136460
URL: http://llvm.org/viewvc/llvm-project?rev=136460&view=rev
Log:
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.
Modified:
llvm/trunk/unittests/ADT/SCCIteratorTest.cpp
Modified: llvm/trunk/unittests/ADT/SCCIteratorTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ADT/SCCIteratorTest.cpp?rev=136460&r1=136459&r2=136460&view=diff
==============================================================================
--- llvm/trunk/unittests/ADT/SCCIteratorTest.cpp (original)
+++ llvm/trunk/unittests/ADT/SCCIteratorTest.cpp Fri Jul 29 02:50:02 2011
@@ -249,14 +249,12 @@
// 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.
@@ -342,9 +340,7 @@
// 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));
+ }
}
}
More information about the llvm-commits
mailing list