summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfche <fche>2007-09-21 18:03:28 +0000
committerfche <fche>2007-09-21 18:03:28 +0000
commit739a3e814f64578666c4d2e25a2bab2b771a8559 (patch)
tree2e9c5913775866a3dbddd4cb954c06f5a678a256
parent5d1374bb3ac11d922f22d4904b43242a1a6eb94f (diff)
downloadsystemtap-steved-739a3e814f64578666c4d2e25a2bab2b771a8559.tar.gz
systemtap-steved-739a3e814f64578666c4d2e25a2bab2b771a8559.tar.xz
systemtap-steved-739a3e814f64578666c4d2e25a2bab2b771a8559.zip
rhbz 300121: optimization bug
-rw-r--r--ChangeLog8
-rw-r--r--elaborate.cxx39
-rw-r--r--testsuite/ChangeLog4
-rw-r--r--testsuite/systemtap.base/optim.exp3
-rw-r--r--testsuite/systemtap.base/optim.stp5
5 files changed, 57 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index 861ee020..28bcf9d5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2007-09-21 Frank Ch. Eigler <fche@elastic.org>
+
+ rhbz #300121
+ * elaborate.cxx (dead_stmtexpr_remover): Add visit_if_statement,
+ visit_foreach_loop, visit_for_loop): Support elision for unbraced
+ statement bodies.
+ (visit_expr_statement): Assert absence of unexpected nesting.
+
2007-09-17 David Smith <dsmith@redhat.com>
PR 1154
diff --git a/elaborate.cxx b/elaborate.cxx
index 094fbbac..621e1a72 100644
--- a/elaborate.cxx
+++ b/elaborate.cxx
@@ -1577,6 +1577,9 @@ struct dead_stmtexpr_remover: public traversing_visitor
session(s), relaxed_p(r), current_stmt(0) {}
void visit_block (block *s);
+ void visit_if_statement (if_statement* s);
+ void visit_foreach_loop (foreach_loop *s);
+ void visit_for_loop (for_loop *s);
// XXX: and other places where stmt_expr's might be nested
void visit_expr_statement (expr_statement *s);
@@ -1595,6 +1598,39 @@ dead_stmtexpr_remover::visit_block (block *s)
}
}
+void
+dead_stmtexpr_remover::visit_if_statement (if_statement *s)
+{
+ statement** last_stmt = current_stmt;
+ current_stmt = & s->thenblock;
+ s->thenblock->visit (this);
+ if (s->elseblock)
+ {
+ current_stmt = & s->elseblock;
+ s->elseblock->visit (this);
+ }
+ current_stmt = last_stmt;
+}
+
+void
+dead_stmtexpr_remover::visit_foreach_loop (foreach_loop *s)
+{
+ statement** last_stmt = current_stmt;
+ current_stmt = & s->block;
+ s->block->visit (this);
+ current_stmt = last_stmt;
+}
+
+void
+dead_stmtexpr_remover::visit_for_loop (for_loop *s)
+{
+ statement** last_stmt = current_stmt;
+ current_stmt = & s->block;
+ s->block->visit (this);
+ current_stmt = last_stmt;
+}
+
+
void
dead_stmtexpr_remover::visit_expr_statement (expr_statement *s)
@@ -1614,7 +1650,8 @@ dead_stmtexpr_remover::visit_expr_statement (expr_statement *s)
varuse_collecting_visitor vut;
s->value->visit (& vut);
- if (vut.side_effect_free_wrt (focal_vars))
+ if (vut.side_effect_free_wrt (focal_vars) &&
+ *current_stmt == s) // we're not nested any deeper than expected
{
if (session.verbose>2)
clog << "Eliding side-effect-free expression "
diff --git a/testsuite/ChangeLog b/testsuite/ChangeLog
index 6f523a83..ec9c74aa 100644
--- a/testsuite/ChangeLog
+++ b/testsuite/ChangeLog
@@ -1,3 +1,7 @@
+2007-09-21 Frank Ch. Eigler <fche@elastic.org>
+
+ * systemtap.base/optim.exp/stp: New test for rhbz# 300121.
+
2007-09-18 David Smith <dsmith@redhat.com>
* systemtap.base/procfs.exp: New test case.
diff --git a/testsuite/systemtap.base/optim.exp b/testsuite/systemtap.base/optim.exp
index 23735af6..a2bfd3ab 100644
--- a/testsuite/systemtap.base/optim.exp
+++ b/testsuite/systemtap.base/optim.exp
@@ -5,9 +5,10 @@ set ok 0
expect {
-timeout 120
-re {i=1} { incr ok }
+ -re {j=2} { incr ok }
timeout { fail "$test (timeout)" }
eof { }
}
close
wait
-if {$ok == 1} { pass $test } { fail $test }
+if {$ok == 2} { pass $test } { fail $test }
diff --git a/testsuite/systemtap.base/optim.stp b/testsuite/systemtap.base/optim.stp
index 6ca722a6..915a65da 100644
--- a/testsuite/systemtap.base/optim.stp
+++ b/testsuite/systemtap.base/optim.stp
@@ -3,7 +3,12 @@ function func(i) {
array[i++] = 0;
return i;
}
+function bart() { # rhbz# 300121
+ if (1) var=2 else dummy=0
+ return var
+}
probe begin {
printf ("i=%d\n", func(0))
+ printf ("j=%d\n", bart())
exit ()
}