]> sourceware.org Git - systemtap.git/commitdiff
PR17860: match foreach logic in tmpcounter and unparser
authorJonathan Lebon <jlebon@redhat.com>
Fri, 16 Jan 2015 18:29:40 +0000 (13:29 -0500)
committerJonathan Lebon <jlebon@redhat.com>
Fri, 23 Jan 2015 14:24:39 +0000 (09:24 -0500)
This patch fixes PR17860 by ensuring that tmpvars are declared in
c_tmpcounter::visit_foreach_loop() in the same order as they are used in
c_unparser::visit_foreach_loop().

translate.cxx

index 5307d4cbed38f67fa16518c3192406e572417f3c..d863683bb183dfdd6b480c07995073681d4fe018 100644 (file)
@@ -3751,6 +3751,19 @@ c_tmpcounter::visit_foreach_loop (foreach_loop *s)
   hist_op *hist;
   classify_indexable (s->base, array, hist);
 
+  // Create a temporary for the loop limit counter and the limit
+  // expression result.
+  if (s->limit)
+    {
+      tmpvar res_limit = parent->gensym (pe_long);
+      res_limit.declare(*parent);
+
+      s->limit->visit (this);
+
+      tmpvar limitv = parent->gensym (pe_long);
+      limitv.declare(*parent);
+    }
+
   if (array)
     {
       itervar iv = parent->getiter (array);
@@ -3788,19 +3801,6 @@ c_tmpcounter::visit_foreach_loop (foreach_loop *s)
       load_aggregate (hist->stat);
     }
 
-  // Create a temporary for the loop limit counter and the limit
-  // expression result.
-  if (s->limit)
-    {
-      tmpvar res_limit = parent->gensym (pe_long);
-      res_limit.declare(*parent);
-
-      s->limit->visit (this);
-
-      tmpvar limitv = parent->gensym (pe_long);
-      limitv.declare(*parent);
-    }
-
   parent->visit_foreach_loop_value(this, s);
 }
 
@@ -3819,7 +3819,6 @@ c_unparser::visit_foreach_loop (foreach_loop *s)
   if (array)
     {
       mapvar mv = getmap (array->referent, s->tok);
-      itervar iv = getiter (array);
       vector<var> keys;
 
       // NB: structure parallels for_loop
@@ -3905,10 +3904,6 @@ c_unparser::visit_foreach_loop (foreach_loop *s)
 
       // NB: sort direction sense is opposite in runtime, thus the negation
 
-      if (mv.is_parallel())
-       aggregations_active.insert(mv.value());
-      o->newline() << iv << " = " << iv.start (mv) << ";";
-
       tmpvar *limitv = NULL;
       if (s->limit)
       {
@@ -3917,6 +3912,12 @@ c_unparser::visit_foreach_loop (foreach_loop *s)
          o->newline() << *limitv << " = 0LL;";
       }
 
+      if (mv.is_parallel())
+       aggregations_active.insert(mv.value());
+
+      itervar iv = getiter (array);
+      o->newline() << iv << " = " << iv.start (mv) << ";";
+
       vector<tmpvar *> array_slice_vars;
       // store the the variables corresponding to the index of the array slice
       // as temporary variables
@@ -4035,12 +4036,6 @@ c_unparser::visit_foreach_loop (foreach_loop *s)
       // Iterating over buckets in a histogram.
       assert(s->indexes.size() == 1);
       assert(s->indexes[0]->referent->type == pe_long);
-      var bucketvar = getvar (s->indexes[0]->referent);
-
-      aggvar agg = gensym_aggregate ();
-
-      var *v = load_aggregate(hist->stat, agg);
-      v->assert_hist_compatible(*hist);
 
       tmpvar *res_limit = NULL;
       tmpvar *limitv = NULL;
@@ -4055,6 +4050,13 @@ c_unparser::visit_foreach_loop (foreach_loop *s)
          o->newline() << *limitv << " = 0LL;";
        }
 
+      var bucketvar = getvar (s->indexes[0]->referent);
+
+      aggvar agg = gensym_aggregate ();
+
+      var *v = load_aggregate(hist->stat, agg);
+      v->assert_hist_compatible(*hist);
+
       record_actions(1, s->tok, true);
       o->newline() << "for (" << bucketvar << " = 0; "
                   << bucketvar << " < " << v->buckets() << "; "
This page took 0.040095 seconds and 5 git commands to generate.