Skip to content

Commit e58cf9b

Browse files
shenjunjiekodafacebook-github-bot
authored andcommitted
[labs] update labs README (#1834)
Summary: This PR slightly optimized and supplemented the content of the resource leak labs README, as well as updated APIs used in the doc. Pull Request resolved: #1834 Reviewed By: ngorogiannis Differential Revision: D75443083 Pulled By: davidpichardie fbshipit-source-id: 5d7fab6ffcb5e06810993e425dbc4c3d41a8a21b
1 parent dc195a4 commit e58cf9b

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

infer/src/labs/README.md

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ Using Docker is the fastest way: you do not need to clone the Infer repository a
2020

2121
```shell
2222
cd /infer
23-
git branch --unset-upstream
24-
git pull
2523
git branch --set-upstream-to=origin/main master
2624
git pull
2725
cp -av /infer/. /infer-host
@@ -104,7 +102,7 @@ Let's stick with just an integer domain to keep things simple until (5).
104102

105103
(a) Run your checker on [LeaksBranch.java](https://github.com/facebook/infer/blob/main/infer/tests/codetoanalyze/java/lab/LeaksBranch.java). Uh oh, it crashed! Fix it by implementing `join` for your domain.
106104

107-
(b) Now run on [LeaksLoop.java](https://github.com/facebook/infer/blob/main/infer/tests/codetoanalyze/java/lab/LeaksLoop.java), and implement `widen`. Hmm... There's a termination bug in the abstract domain–do you see it?
105+
(b) Now run on [LeaksLoop.java](https://github.com/facebook/infer/blob/main/infer/tests/codetoanalyze/java/lab/LeaksLoop.java), and implement `widen` and `leq`. Hmm... There's a termination bug in the abstract domain–do you see it?
108106

109107
(c) Time for a richer domain! A classic solution to this problem in abstract interpretation is to add a `Top` value that is larger than any integer.
110108

@@ -135,22 +133,21 @@ Augment the summary type with state to indicate whether the current procedure re
135133

136134
This improvement should allow your analysis to pass the tests in [LeaksInterprocedural.java](https://github.com/facebook/infer/blob/main/infer/tests/codetoanalyze/java/lab/LeaksInterprocedural.java).
137135

138-
Hint: What do return values look like in infer? They are assignments to a special variable, detected by `Var.is_return`. You may also want to match only return variables of some specific object type. Use this code to look at the classname of the type of the return value:
136+
Hint: What do return values look like in infer? They are assignments to a special variable, detected by `Pvar.is_return`. You may also want to match only return variables of some specific object type. Use this code to look at the classname of the type of the return value:
139137

140138
```OCaml
141-
| Assign
142-
(Base (ret, {Typ.desc= Typ.Tptr ({Typ.desc= Typ.Tstruct ret_typename}, _)}), _rhs_exp, _loc)
143-
when Var.is_return ret ->
139+
| Store {e1= Lvar ret_var; e2= _rhs; typ= {desc= Tptr ({desc= Tstruct ret_typename}, _)}; loc= _loc}
140+
when Pvar.is_return ret_var ->
144141
```
145142

146-
Then `ret_var` is the return variable (if `Var.is_return ret_var` returns true), of type `ret_typename` (really `ret_typename*` in infer's intermediate representation).
143+
Then `ret_var` is the return variable (if `Pvar.is_return ret_var` returns true), of type `ret_typename` (really `ret_typename*` in infer's intermediate representation).
147144

148145

149146
## (5) Access paths
150147

151148
(a) Change the simple counting domain to a domain that overapproximates the set of storage locations that hold a resource. As a concrete goal, the new domain should allow you to print the name of the resource(s) that leak in the error message (rather than just the number of resources). The new domain should also allow your analysis to get the correct answer on your false negative and false positive tests from 2(d) and 2(e). Think about the following questions when designing your new domain:
152149

153-
- How should we abstract storage locations? Is abstracting the stack program variables (`Var.t`) enough, or do we need an abstraction of the heap as well?
150+
- How should we abstract storage locations? Is abstracting the stack program variables (`Pvar.t`) enough, or do we need an abstraction of the heap as well?
154151

155152
- How will we handle aliasing (storage locations that store the same address)? More precisely, how to handle assignement? We will need to make some simplifying assumptions and cut some corners here. Developing a full memory model that accounts for aliasing perfectly is out of the scope of this lab (check out how the Pulse analysis does it!).
156153

@@ -160,7 +157,7 @@ Then `ret_var` is the return variable (if `Var.is_return ret_var` returns true),
160157

161158
- It's okay for the domain to diverge in certain cases for the purpose of this lab. Can you write a method that would make your checker diverge?
162159

163-
(b) Write some tests that demonstrate the limitations of your new domain: both false positives (names prefixed with `FP_` and false negatives (prefixed with `FN_`). Add them to [LeaksAccessPaths.java](https://github.com/facebook/infer/blob/main/infer/tests/codetoanalyze/java/lab/LeaksAccessPath.java).
160+
(b) Write some tests that demonstrate the limitations of your new domain: both false positives (names prefixed with `FP_`) and false negatives (prefixed with `FN_`). Add them to [LeaksAccessPaths.java](https://github.com/facebook/infer/blob/main/infer/tests/codetoanalyze/java/lab/LeaksAccessPaths.java).
164161

165162
(c) Augment the summary type with state to indicate formals that are closed by the current function. This should allow your analysis to pass the tests in [LeaksAccessPathsInterprocedural.java](https://github.com/facebook/infer/blob/main/infer/tests/codetoanalyze/java/lab/LeaksAccessPathsInterprocedural.java).
166163

@@ -173,6 +170,6 @@ Hint: You will find the `FormalMap` module useful for this. This module lets you
173170

174171
(b) Try running on real code! The instructions [here](http://fm.csl.sri.com/SSFT17/infer-instr.html) have several suggestions for open-source Android apps to point your analysis at. Try `./gradlew assembleDebug -x test` first to make sure everything builds correctly without Infer (if not, you are probably missing some dependencies--the error messages should guide you). Once that's working, try
175172
`./gradlew clean; infer run --resource-leak-lab-only -- ./gradlew assembleDebug -x test`.
176-
- Found a real bug? Bonus points! Send a pull request to fix it! Very frequently, the best fix is to use try-with-resources.
173+
- Found a real bug? Bonus points! Send a pull request to fix it! Very frequently, the best fix is to use `try-with-resources`.
177174
- Found a false positive in your analysis? Try re-running Infer with `--debug` and see if you can narrow down the root cause/fix it.
178175
- How does your analysis compare to Infer's production resource leak analysis? Run with `infer -- <gradle command>` to see if your analysis finds bugs that Infer misses, or vice versa.

0 commit comments

Comments
 (0)