summaryrefslogtreecommitdiff
path: root/unittests
diff options
context:
space:
mode:
authorDuncan Sands <baldrick@free.fr>2011-07-29 07:50:02 +0000
committerDuncan Sands <baldrick@free.fr>2011-07-29 07:50:02 +0000
commit6815ff07d45e5905b2a5c1e1df8f09ae8c38e5de (patch)
tree358214fc3a2e189f13ab271fe6da06e6f8d1a5ea /unittests
parent3c036e520e1fb19f2dd4fdcbc7e6881984dc72f9 (diff)
downloadllvm-6815ff07d45e5905b2a5c1e1df8f09ae8c38e5de.tar.gz
llvm-6815ff07d45e5905b2a5c1e1df8f09ae8c38e5de.tar.bz2
llvm-6815ff07d45e5905b2a5c1e1df8f09ae8c38e5de.tar.xz
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
Diffstat (limited to 'unittests')
-rw-r--r--unittests/ADT/SCCIteratorTest.cpp16
1 files changed, 6 insertions, 10 deletions
diff --git a/unittests/ADT/SCCIteratorTest.cpp b/unittests/ADT/SCCIteratorTest.cpp
index c3ffce59ab..00fa0665dd 100644
--- a/unittests/ADT/SCCIteratorTest.cpp
+++ b/unittests/ADT/SCCIteratorTest.cpp
@@ -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.
@@ -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));
+ }
}
}