[Soot-list] How to determine whether there exists a use for a variable definition later on in the cfg

John Dean jdean4 at kc.rr.com
Fri Jul 27 22:57:23 EDT 2012


All,

After much testing, it appears that the getUsesOf(Unit)  method call
retrieves only variable uses that are within the loop and not the ones that
I'm interested in - the ones outside of the loop. My guess is that that's a
limitation due to the difficulty of tracking down dependencies. Does anyone
know of a way to successfully retrieve uses for a variable, anywhere in a
method, after the variable has been assigned?

If you want to see my tests to make sure I'm thinking about things properly,
here is a source code fragment that I've tested:

int x = 0;
while (x < 2)
{
    x = x + 1;
}
int y = x;

And here are the generated units for that code:

x = 0;

label0:
  nop;
  if x < 2 goto label1;
  goto label2;

label1:
  nop;
  temp$1 = x;
  temp$2 = temp$1 + 1;
  x = temp$2;
  goto label0;

label2:
  nop;
  y = x;
  return;

When I run the following code, unitValueBoxPairList is an empty list.
Apparently, getUsesOf does not bother to go to the label2 code to find x
being used.

defs = new SimpleLocalDefs(g);
uses = new SimpleLocalUses(g, defs);
unitValueBoxPairList = (List<UnitValueBoxPair>) uses.getUsesOf(stmt);

1. Is my thinking correct?

2. Does anyone know of a way to successfully retrieve uses for a variable,
anywhere in a method, after the variable has been assigned?

Thanks,
John


-----Original Message-----
From: phil.pratt.szeliga at gmail.com [mailto:phil.pratt.szeliga at gmail.com] On
Behalf Of Phil Pratt-Szeliga
Sent: Friday, July 27, 2012 12:58 PM
To: john.dean at park.edu
Cc: soot-list at sable.mcgill.ca
Subject: Re: [Soot-list] How to determine whether there exists a use for a
variable definition later on in the cfg

Hi John,

> Or better yet, I suppose
> I can use List's contains method with my list of loop statements to 
> test whether a retrieved statement (from getUsesOf) is in my list of 
> loop statements. That should work because the contains method relies 
> on the equals method.

Yes, this is what I had in mind. :)

Phil Pratt-Szeliga
Syracuse University

-----Original Message-----
From: John Dean [mailto:jdean4 at kc.rr.com] 
Sent: Friday, July 27, 2012 12:24 PM
To: 'Phil Pratt-Szeliga'
Cc: 'soot-list at sable.mcgill.ca'
Subject: RE: [Soot-list] How to determine whether there exists a use for a
variable definition later on in the cfg

Phil (and anyone else?),
Thanks for the suggestion!

Fortuanately, I've already borrowed/written code to detect loops.

I think you are saying that if I use the default equals method from the
Object class (which tests for the same reference address) to compare one of
the retrieved units from getUsesOf() with each unit in the loop, equals will
return true only if the units are the same exact unit reference (both from
within the loop)? Is that right?

So, for example, if there's an x = y statement inside the loop and there's
also an x = y statement outside of the loop, then those 2 statements will
return false when compared using the equals method. Or better yet, I suppose
I can use List's contains method with my list of loop statements to test
whether a retrieved statement (from getUsesOf) is in my list of loop
statements. That should work because the contains method relies on the
equals method.

Does it sound like I'm on the right track?

Thanks,
John




More information about the Soot-list mailing list