Bug 11590 - optimized pre/postfix operators on variable throw away initial variable assignment
Summary: optimized pre/postfix operators on variable throw away initial variable assig...
Status: RESOLVED FIXED
Alias: None
Product: systemtap
Classification: Unclassified
Component: translator (show other bugs)
Version: unspecified
: P2 normal
Target Milestone: ---
Assignee: Unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-05-12 09:28 UTC by Mark Wielaard
Modified: 2021-10-19 07:05 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Mark Wielaard 2010-05-12 09:28:22 UTC
The following testcase shows that the original assignment of the variable is
ignored:

probe begin {

        a = 5

        // printf("%d ", a)
        printf("%d ", (a++))
        printf("%d ", (++a))
        printf("%d ", (a--))
        printf("%d\n", (--a))
        exit()
}

$ stap test.stp
0 2 2 0

If we uncomment the actually first use the original assigned value of a things
look correct:

$ stap test.stp
5 5 7 7 5

This is an translation optimization issue, the original script also prints out
the correct value when unoptimized:

$ stap -u test.stp
5 7 7 5
Comment 1 Mark Wielaard 2010-05-12 09:44:28 UTC
This seems to have been caused by commit 982b88bd which solved bug #6954.

commit 982b88bd950381434a8325e550eff9df59f59dcd
Author: Wenji Huang <wenji.huang@oracle.com>
Date:   Thu Jan 28 14:16:43 2010 +0800

    PR6954: make ++/-- operation trigger automatic global printing
    
    * staptree.cxx (varuse_collecting_visitor::visit_arrayindex):
      Regard operations as pure writes.
    * testsuite/systemtap.base/global_end.exp: Add test case.
    * testsuite/systemtap.base/global_end.stp: Ditto.

Note comment #3 of that bug:

"FWIW, I wonder why we didn't just go this route earlier.  I worry
that pretending that ++ only writes to its argument may mess up
some optimization, I can't think of one right now.  We'll keep
this special case in mind."

Reverting this commit fixes this bug (but obviously introduces bug #6954 again).
Comment 2 Mark Wielaard 2010-05-12 12:43:11 UTC
commit d1cf0b627cfc9002b54c2ad40507de9ee6a2ce90
Author: Mark Wielaard <mjw@redhat.com>
Date:   Wed May 12 14:39:55 2010 +0200

    Add testcase for PR11590 optimized pre/postfix operators
    
    * testsuite/systemtap.base/prepost_optim.stp: New test.
    * testsuite/systemtap.base/prepost_optim.exp: Harness.

commit ad8c38ffc62200d6ba6ebc0b0339967cdd84669a
Author: Mark Wielaard <mjw@redhat.com>
Date:   Wed May 12 14:31:59 2010 +0200

    Add testcase for PR6954 ++ operations not triggering automatic global printing
    
    * testsuite/systemtap.base/global_end_var.stp: New test.
    * testsuite/systemtap.base/global_end.exp: Add xfail.

commit 980759f3da625c5697440efc1bfda046c247866e
Author: Mark Wielaard <mjw@redhat.com>
Date:   Wed May 12 14:16:26 2010 +0200

    PR11590 Revert "PR6954: make ++/-- operation trigger automatic global printing"
    
    This reverts commit 982b88bd950381434a8325e550eff9df59f59dcd.
    
    Pretending that pre/postfix ++/-- operations only writes to its argument
    messes up the optimization of a variable that is assigned and then
    only used through post/prefix ++/--operators.
Comment 3 David John 2021-10-19 07:05:09 UTC Comment hidden (spam)