aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/validation
diff options
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2017-04-26 12:21:21 +0200
committerLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2017-05-12 00:22:05 +0200
commit51cfbc90a5e1462fcd624a1598ecd985a508a5d6 (patch)
treeb71db703021828067a62313e7aff9456fd2f1608 /validation
parent7c40199410fa97772affd790bb5200d55219d041 (diff)
downloadsparse-dev-51cfbc90a5e1462fcd624a1598ecd985a508a5d6.tar.gz
fix: kill unreachable BBs after killing a child
When simplifying a switch into a simple branch all the now unused children of the current BB must be removed. If one of these children become now orphaned, it is directly killed (it will need to be killed soon or later since it is unreachable). However, if one of the killed children is the header of a loop where some variables are updated this may cause problems. Indeed, by killing the header (which contains the phisrc of the entry value of the variable) the whole loop may become unreachable but is not killed yet, OTOH simplification of the associated OP_PHI may create a cycle which may then be detected later by simplify_one_memop() which will issue a "crazy programmer" warning while the programmer was innocent. This situation can be seen in code like: int *p; switch (i - i) { // will be optimized to 0 case 0: // will be the simple branch return 0; case 1: // will be optimized away p = ptr; do { // will be an unreachable loop *p++ = 123; } while (--i); } Fix this by calling kill_unreachable_bbs() after having simplified the switch into a branch. This will avoid to create a cycle with because of the removed phisrc in the header and as an added benefit will avoid to waste time trying to simplify BBs that are unreachable. In addition, it's now useless to call kill_bb() for each removed switch's children as kill_unreachable_bbs() will do that too. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Diffstat (limited to 'validation')
-rw-r--r--validation/crazy02-not-so.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/validation/crazy02-not-so.c b/validation/crazy02-not-so.c
new file mode 100644
index 00000000..fe713358
--- /dev/null
+++ b/validation/crazy02-not-so.c
@@ -0,0 +1,22 @@
+int foo(int *ptr, int i)
+{
+ int *p;
+
+ switch (i - i) { // will be optimized to 0
+ case 0:
+ return 0;
+ case 1: // will be optimized away
+ p = ptr;
+ do { // will be an unreachable loop
+ *p++ = 123;
+ } while (--i);
+ break;
+ }
+
+ return 1;
+}
+
+/*
+ * check-name: crazy02-not-so.c
+ * check-command: sparse -Wno-decl $file
+ */