Fix bad CFG construction bug when handling C++ 'try' statements.
This code assigned the last created CFGBlock* to the variable 'Block',
which is a scratch variable which is null'ed out after a block is
completed. By assigning the last created block to 'Block', we start
editing a completed block, inserting CFGStmts that should be in
another block. This was the case with 'try'. The test case that
showed this had a while loop inside a 'try', and the logic before
the while loop was being included as part of the "condition block"
for the loop. This showed up as a bogus dead store, but could
have lots of implications.
Turns out this bug was replicated a few times within CFG.cpp, so
I went and fixed up those as well.
llvm-svn: 167788
diff --git a/clang/test/Analysis/dead-stores.cpp b/clang/test/Analysis/dead-stores.cpp
index 341363a..86d84f0 100644
--- a/clang/test/Analysis/dead-stores.cpp
+++ b/clang/test/Analysis/dead-stores.cpp
@@ -126,3 +126,26 @@
return 1;
}
+
+int test_6_aux(unsigned x);
+
+void test_6() {
+ unsigned currDestLen = 0; // no-warning
+ try {
+ while (test_6_aux(currDestLen)) {
+ currDestLen += 2; // no-warning
+ }
+ }
+ catch (void *) {}
+}
+
+void test_6b() {
+ unsigned currDestLen = 0; // no-warning
+ try {
+ while (test_6_aux(currDestLen)) {
+ currDestLen += 2; // expected-warning {{Value stored to 'currDestLen' is never read}}
+ break;
+ }
+ }
+ catch (void *) {}
+}