[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
Sat Jul 28 14:14:35 EDT 2012


Hi all,

I attempted to send this same email 6 hours ago, but I'm afraid that it
might have gotten lost in cyberspace since I didn't receive it as a
subscriber to the soot mailing list. Thus, I'm sending it again. Forgive me
if you have already received it.

As a follow-up to my email below this one....
If I'm correct that SimpleLocalUses.getUsesOf(Unit)  retrieves only variable
uses that are within the loop and not the ones outside of the loop, then
should I try to use the AllVariableUses class instead? And call its
getUsesForLocal method?

If using AllVariableUses.getUsesForLocal is the proper way to go, then how
do I create an AllVariableUses object? The api defines the constructor as
this:

AllVariableUses(ASTMethodNode node)

But then there's the problem of creating an ASTMethodNode object. It's
constructor is as follows:

ASTMethodNode(List<Object> body)

The api doesn't tell me what sort of List<Object> to use.

As you can see, I'm struggling to solve my problem. Any suggestions would be
greatly appreciated.

Thanks,
John

-----Original Message-----
From: soot-list-bounces at sable.mcgill.ca
[mailto:soot-list-bounces at sable.mcgill.ca] On Behalf Of John Dean
Sent: Friday, July 27, 2012 9:57 PM
To: 'Phil Pratt-Szeliga'; 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

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


_______________________________________________
Soot-list mailing list
Soot-list at sable.mcgill.ca
http://mailman.cs.mcgill.ca/mailman/listinfo/soot-list



More information about the Soot-list mailing list