Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Steensgaard implementation and adding ctx sensitivity at call sites #147

Merged
merged 31 commits into from
Feb 27, 2024

Conversation

yousifpatti
Copy link
Contributor

@yousifpatti yousifpatti commented Dec 5, 2023

  • Steensgaard base class
  • Stack support
  • Globals support
    - [ ] Heap Support In the coming iteration
  • Context Sensitivity Set based SSA

@yousifpatti yousifpatti marked this pull request as ready for review February 12, 2024 01:34
@yousifpatti yousifpatti requested a review from ailrst February 12, 2024 01:35
Copy link
Contributor

@ailrst ailrst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't look like the ssa_id is doing the right thing, so the steensgaard and constprop with ssa probably don't work correctly but the ANR and RNA are probably good, although it would be good to have some basic tests.


sealed trait Expr {
var ssa_id: mutable.Set[Int] = mutable.Set[Int]()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this only need to be defined on variables? It should also be a val instead since the set itself is mutable.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expressions are immutable case classes, so for expressions in different statements to be distinguished this might need to be a real field in the register and local var classes. But there might be a better approach. Currently it seems like the variable "R0" gets the same ssa_id everywhere in the program.

Copy link
Contributor Author

@yousifpatti yousifpatti Feb 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will have to add this as a field for the Variable trait as Register and LocalVar are immutable case classes. Would this fix the issue?

* - Each variable has a set of versions
* - New assignments create new versions and replaces any new versions
*/
object SSAForm {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make this a class? Alternatively, far as I can tell all the members are temporary and can be private and cleared when calling applySSA?

(block, v.name),
context.getOrElseUpdate((proc, v.name), mutable.Set(getMax(v.name)))
)
})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like its doing a kind of use-def lookup which I don't think will do the right thing without assigning the SSA form indexes in the order of definitions?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On second look, this is just creating new SSA IDs without caring about the specific definition? In that case it is ok?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is meant to create a new SSA ID without relying on any particular order if the variable (register) has not been defined before. If the variable has been defined before in that procedure, then we want to assume the last definition applies. The caller of transformVariables is responsible for controlling the order of processing statements.


def applySSA(program: Program): Unit = {
for (proc <- program.procedures) {
for (block <- proc.blocks) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above, the order of this is not defined and it may not match cfg order. If we visit a block before its predecessors the ssa ids of the variables won't correspond to earlier assignments. Could maybe just use a stack and and Block.nextBlocks() to iterate the blocks instead.

override def hashCode(): Int = regionIdentifier.hashCode() * start.hashCode()
override def equals(obj: Any): Boolean = obj match {
case s: StackRegion => s.start == start && s.regionIdentifier == regionIdentifier
case s: StackRegion => s.start == start && s.regionIdentifier.equals(regionIdentifier)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use == rather than equals, they mean the same thing in Scala. Reference equality is .eq().

m - indirectCall.target
case localAssign: LocalAssign =>
m = m.diff(localAssign.rhs.variables)
if (ignoreRegions.contains(localAssign.lhs)) return m
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return is deprecated so better to use if (_) then m else m + localassign.lhs

@ailrst ailrst mentioned this pull request Feb 19, 2024
3 tasks
@yousifpatti yousifpatti requested a review from ailrst February 21, 2024 03:18
@l-kent
Copy link
Contributor

l-kent commented Feb 26, 2024

How much left is there to do here before we can look at merging this?

@yousifpatti
Copy link
Contributor Author

I am currently writing tests and it will need to be moved to use the IR iterator at some point (working on it in another branch). The Points-to constraints may need to be refined as they are not precisely Steensgaard constraints because they were not meant for Binary-level pointer analysis. The current constraints are a highly modified version of the Steensgaard constraints and work is needed to verify soundness.
The current progress can be merged through this PR while those aspects are being worked on. I will just get it up to date with main first and resubmit PR review request.

@l-kent
Copy link
Contributor

l-kent commented Feb 26, 2024

Ah, what I'm really interested in everything being moved over to the new iterator, and I was wanting to start work on that, but it's difficult to do so when there's significant outstanding changes to the existing analyses

The simplest thing would be to merge this branch into staging once the current merge happening there is finished, and then we can merge all of staging into main. It's not an issue if the points-to and Steengaard analyses aren't perfect yet, just as long as nothing else with the existing analyses has regressed.

@yousifpatti yousifpatti force-pushed the yousif-steensgaard-ctx-sensetive branch from 2c7ed92 to d133b75 Compare February 27, 2024 02:58
@yousifpatti yousifpatti changed the base branch from main to staging February 27, 2024 03:30
@l-kent
Copy link
Contributor

l-kent commented Feb 27, 2024

Is this ready to merge into staging now?

@yousifpatti yousifpatti merged commit f8019e3 into staging Feb 27, 2024
@yousifpatti
Copy link
Contributor Author

@l-kent points-to and analyses changes has been merged into staging

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants