Skip to content

Simplified session #6

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

Open
wants to merge 28 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
3c0139c
Major README updates
hohn May 9, 2023
b1db4ec
Add explicit workshop/session support
hohn May 9, 2023
c2d0120
Build database from session support file
hohn May 9, 2023
118abc6
clarify README
hohn May 9, 2023
30e5f43
tree depth change
hohn May 9, 2023
dafd5cc
change to session-based workshop
hohn May 10, 2023
079b7d3
Tangled (extracted) the embedded examples into separate files
hohn May 12, 2023
1540e66
Add the test cases for the session examples
hohn May 12, 2023
ded9d34
Include session examples rather than inlining. Clear up some session…
hohn May 16, 2023
5e1ad9e
Add WIP template for simplification
May 16, 2023
6695f07
Expanded the "Session/Workshop notes" section
hohn May 16, 2023
22126ed
Introduce some predicates at step 4a
hohn May 17, 2023
b444185
Further clarify the goals in "Session/Workshop notes"
hohn May 17, 2023
71153b2
WIP: Update example5. List predicates to be introduced
hohn May 17, 2023
2d30b85
Update example 6
hohn May 17, 2023
8cea58a
Update example7. Prepare to introduce more predicates
hohn May 17, 2023
e790a3c
Added interim step 7a
hohn May 17, 2023
da7781a
Added interim step 7a, detailing some predicate derivation
hohn May 18, 2023
bedd049
Include size comparison in example7b, from 8
hohn May 19, 2023
841a33b
Add session snapshot script
hohn May 20, 2023
c04eebe
Update step 8
hohn May 20, 2023
5a40e93
Clarified the alloc and buffer access check intention
hohn May 22, 2023
646c70f
step 8a: Find /some/ problematic accesses by reverting to simple var+…
hohn May 22, 2023
ea064e5
More on step 9, global value numbering
hohn May 23, 2023
903b752
export to plain markdown to fix github rendering
hohn May 23, 2023
e4e2995
Apply the solution/5 results format to all steps
hohn May 23, 2023
1c733ef
Introduce hashconsing in step 9a to get correct equality comparison
hohn May 23, 2023
c59d8bf
A short note on the structure of directories and their use
hohn May 23, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
step 8a: Find /some/ problematic accesses by reverting to simple var+…
…const checks
  • Loading branch information
hohn committed May 22, 2023
commit 646c70fdc9068119460ffe2c39d43b1092c50b40
21 changes: 9 additions & 12 deletions session-tests/example8a/example8a.expected
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
| test.c:16:17:16:22 | call to malloc | test.c:16:24:16:27 | size | 0 | test.c:19:5:19:17 | access to array | test.c:19:9:19:12 | size | -1 | test.c:15:19:15:22 | size | test.c:15:19:15:22 | size |
| test.c:16:17:16:22 | call to malloc | test.c:16:24:16:27 | size | 0 | test.c:21:5:21:13 | access to array | test.c:21:9:21:12 | size | 0 | test.c:15:19:15:22 | size | test.c:15:19:15:22 | size |
| test.c:28:17:28:22 | call to malloc | test.c:28:24:28:27 | size | 0 | test.c:37:5:37:17 | access to array | test.c:37:9:37:12 | size | -1 | test.c:26:19:26:22 | size | test.c:26:19:26:22 | size |
| test.c:28:17:28:22 | call to malloc | test.c:28:24:28:27 | size | 0 | test.c:39:5:39:13 | access to array | test.c:39:9:39:12 | size | 0 | test.c:26:19:26:22 | size | test.c:26:19:26:22 | size |
| test.c:28:17:28:22 | call to malloc | test.c:28:24:28:27 | size | 0 | test.c:43:9:43:17 | access to array | test.c:43:13:43:16 | size | 0 | test.c:26:19:26:22 | size | test.c:26:19:26:22 | size |
| test.c:28:17:28:22 | call to malloc | test.c:28:24:28:27 | size | 0 | test.c:44:9:44:21 | access to array | test.c:44:13:44:16 | size | 1 | test.c:26:19:26:22 | size | test.c:26:19:26:22 | size |
| test.c:28:17:28:22 | call to malloc | test.c:28:24:28:27 | size | 0 | test.c:45:9:45:21 | access to array | test.c:45:13:45:16 | size | 2 | test.c:26:19:26:22 | size | test.c:26:19:26:22 | size |
| test.c:63:17:63:22 | call to malloc | test.c:63:24:63:33 | alloc_size | 0 | test.c:68:5:68:23 | access to array | test.c:68:9:68:18 | alloc_size | -1 | test.c:51:19:51:28 | alloc_size | test.c:51:19:51:28 | alloc_size |
| test.c:63:17:63:22 | call to malloc | test.c:63:24:63:33 | alloc_size | 0 | test.c:69:5:69:19 | access to array | test.c:69:9:69:18 | alloc_size | 0 | test.c:51:19:51:28 | alloc_size | test.c:51:19:51:28 | alloc_size |
| test.c:63:17:63:22 | call to malloc | test.c:63:24:63:33 | alloc_size | 0 | test.c:73:9:73:23 | access to array | test.c:73:13:73:22 | alloc_size | 0 | test.c:51:19:51:28 | alloc_size | test.c:51:19:51:28 | alloc_size |
| test.c:63:17:63:22 | call to malloc | test.c:63:24:63:33 | alloc_size | 0 | test.c:74:9:74:27 | access to array | test.c:74:13:74:22 | alloc_size | 1 | test.c:51:19:51:28 | alloc_size | test.c:51:19:51:28 | alloc_size |
| test.c:63:17:63:22 | call to malloc | test.c:63:24:63:33 | alloc_size | 0 | test.c:75:9:75:27 | access to array | test.c:75:13:75:22 | alloc_size | 2 | test.c:51:19:51:28 | alloc_size | test.c:51:19:51:28 | alloc_size |
| test.c:16:17:16:22 | call to malloc | test.c:16:24:16:27 | size | test.c:21:5:21:13 | access to array | test.c:21:9:21:12 | size | test.c:15:19:15:22 | size | 0 | test.c:15:19:15:22 | size | 0 |
| test.c:28:17:28:22 | call to malloc | test.c:28:24:28:27 | size | test.c:39:5:39:13 | access to array | test.c:39:9:39:12 | size | test.c:26:19:26:22 | size | 0 | test.c:26:19:26:22 | size | 0 |
| test.c:28:17:28:22 | call to malloc | test.c:28:24:28:27 | size | test.c:43:9:43:17 | access to array | test.c:43:13:43:16 | size | test.c:26:19:26:22 | size | 0 | test.c:26:19:26:22 | size | 0 |
| test.c:28:17:28:22 | call to malloc | test.c:28:24:28:27 | size | test.c:44:9:44:21 | access to array | test.c:44:13:44:16 | size | test.c:26:19:26:22 | size | 0 | test.c:26:19:26:22 | size | 1 |
| test.c:28:17:28:22 | call to malloc | test.c:28:24:28:27 | size | test.c:45:9:45:21 | access to array | test.c:45:13:45:16 | size | test.c:26:19:26:22 | size | 0 | test.c:26:19:26:22 | size | 2 |
| test.c:63:17:63:22 | call to malloc | test.c:63:24:63:33 | alloc_size | test.c:69:5:69:19 | access to array | test.c:69:9:69:18 | alloc_size | test.c:51:19:51:28 | alloc_size | 0 | test.c:51:19:51:28 | alloc_size | 0 |
| test.c:63:17:63:22 | call to malloc | test.c:63:24:63:33 | alloc_size | test.c:73:9:73:23 | access to array | test.c:73:13:73:22 | alloc_size | test.c:51:19:51:28 | alloc_size | 0 | test.c:51:19:51:28 | alloc_size | 0 |
| test.c:63:17:63:22 | call to malloc | test.c:63:24:63:33 | alloc_size | test.c:74:9:74:27 | access to array | test.c:74:13:74:22 | alloc_size | test.c:51:19:51:28 | alloc_size | 0 | test.c:51:19:51:28 | alloc_size | 1 |
| test.c:63:17:63:22 | call to malloc | test.c:63:24:63:33 | alloc_size | test.c:75:9:75:27 | access to array | test.c:75:13:75:22 | alloc_size | test.c:51:19:51:28 | alloc_size | 0 | test.c:51:19:51:28 | alloc_size | 2 |
12 changes: 8 additions & 4 deletions session/example8a.ql
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,20 @@ where
// Same initializer variable
bufferBase.(VariableAccess).getTarget() = bufInit and
accessBase.(VariableAccess).getTarget() = accessInit and
bufInit = accessInit
// +++
// Identify questionable differences
select buffer, bufferBase, bufferOffset, access, accessBase, accessOffset, bufInit, accessInit
bufInit = accessInit and
// +++
// Identify questionable differences
accessOffset >= bufferOffset
select buffer, bufferBase, access, accessBase, bufInit, bufferOffset, accessInit, accessOffset

/**
* Extract base and offset from y = base+offset and y = base-offset. For others, get y and 0.
*
* For cases like
* buf[alloc_size + 1];
* ^^^^^^^^^^^^^^ expr
* ^^^^^^^^^^ base
* ^^^ offset
*
* The more general
* buf[sz * x * y - 1];
Expand Down
42 changes: 18 additions & 24 deletions session/session.org
Original file line number Diff line number Diff line change
Expand Up @@ -446,19 +446,6 @@ To address these, take the query from the previous exercise and
- This only handles very specific cases. Constructing counterexamples is easy.
- We will address this in the next section.

*** TODO incoporate
#+BEGIN_SRC java
predicate isOffsetOutOfBoundsConstant(
ArrayExpr access, FunctionCall source, int allocSize, int accessOffset
) {
ensureSameFunction(access, source) and
// allocatedBufferArrayAccess(access, source) and
allocSize = getMaxStatedValue(source.getArgument(0)) and
accessOffset = getFixedArrayOffset(access) and
accessOffset >= allocSize
}
#+END_SRC

*** Solution:
#+INCLUDE: "example8.ql" src java

Expand All @@ -482,9 +469,25 @@ To address these, take the query from the previous exercise and
constants that flow to a given expression. Another approach is global value
numbering, used next.

** Step 8a
Find problematic accesses by reverting to some /simple/ =var+const= checks using
=accessOffset= and =bufferOffset=.

Note:
- These will flag some false positives.
- The product expression =sz * x * y= is not easily checked for equality.
These are addressed in the next step.

*** Solution:
#+INCLUDE: "example8a.ql" src java

*** First 5 results
#+INCLUDE: "../session-tests/example8a/example8a.expected" :lines "-6"’

** Step 9 -- Global Value Numbering
Range analyis won't bound =sz * x * y=, so switch to global value
numbering.
Range analyis won't bound =sz * x * y=, and simpl equality checks don't work at
the structure level, so switch to global value numbering.

This is the case in the last test case,
#+begin_example
void test_gvn_var(unsigned long x, unsigned long y, unsigned long sz)
Expand Down Expand Up @@ -524,15 +527,6 @@ To address these, take the query from the previous exercise and
#+end_example
we have to "evaluate" the expressions -- or at least bound them.

*** DONE incorporate
Done by =ensureSameFunction= instead.
#+BEGIN_SRC java
predicate allocatedBufferArrayAccess(ArrayExpr access, FunctionCall alloc) {
alloc.getTarget().hasName("malloc") and
DataFlow::localExprFlow(alloc, access.getArrayBase())
}
#+END_SRC

*** TODO incoporate
#+BEGIN_SRC java
int getFixedArrayOffset(ArrayExpr access) {
Expand Down