Skip to content

C++: Implement isUnreachableInCall#13603

Merged
MathiasVP merged 6 commits intogithub:mainfrom
MathiasVP:implement-is-unreachable-in-call-2
Jun 30, 2023
Merged

C++: Implement isUnreachableInCall#13603
MathiasVP merged 6 commits intogithub:mainfrom
MathiasVP:implement-is-unreachable-in-call-2

Conversation

@MathiasVP
Copy link
Copy Markdown
Contributor

isUnreachableInCall makes use of the already-existing call context computed in the dataflow library to rule out infeasible dataflow paths in a function body based on the passed arguments.

IIRC, @aschackmull mentioned that the implementation of this feature inside the dataflow library isn't super efficient, so I'm marking this as a draft while we run DCA to estimate the cost of this vs. the benefits provided (I'm looking at you FPs in cpp/constant-array-overflow!)

@github-actions github-actions Bot added the C++ label Jun 28, 2023
@MathiasVP MathiasVP marked this pull request as ready for review June 28, 2023 16:38
@MathiasVP MathiasVP requested a review from a team as a code owner June 28, 2023 16:38
@MathiasVP
Copy link
Copy Markdown
Contributor Author

DCA looks good: performance looks unchanged, and it's removing a small amount of FPs in various queries.

@MathiasVP MathiasVP added the no-change-note-required This PR does not need a change note label Jun 28, 2023
Copy link
Copy Markdown
Contributor

@jketema jketema left a comment

Choose a reason for hiding this comment

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

Two small comments, otherwise LGTM.

Comment thread cpp/ql/test/library-tests/dataflow/dataflow-tests/test.cpp Outdated
| test.cpp:136:9:136:16 | PointerAdd: ... += ... | test.cpp:143:18:143:21 | asdf | test.cpp:138:13:138:15 | arr | This pointer arithmetic may have an off-by-2 error allowing it to overrun $@ at this $@. | test.cpp:142:10:142:13 | asdf | asdf | test.cpp:138:12:138:15 | Load: * ... | read |
| test.cpp:151:5:151:11 | PointerAdd: access to array | test.cpp:148:23:148:28 | buffer | test.cpp:151:5:151:11 | access to array | This pointer arithmetic may have an off-by-1 error allowing it to overrun $@ at this $@. | test.cpp:147:19:147:24 | buffer | buffer | test.cpp:151:5:151:15 | Store: ... = ... | write |
| test.cpp:162:5:162:10 | PointerAdd: access to array | test.cpp:159:25:159:29 | array | test.cpp:162:5:162:10 | access to array | This pointer arithmetic may have an off-by-1 error allowing it to overrun $@ at this $@. | test.cpp:158:10:158:14 | array | array | test.cpp:162:5:162:19 | Store: ... = ... | write |
| test.cpp:191:27:191:30 | PointerAdd: access to array | test.cpp:201:14:201:20 | buffer2 | test.cpp:191:27:191:30 | access to array | This pointer arithmetic may have an off-by-1 error allowing it to overrun $@ at this $@. | test.cpp:200:19:200:25 | buffer2 | buffer2 | test.cpp:191:27:191:30 | Load: access to array | read |
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think the test annotation needs to be updated too.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

There's still a FP on that line, so we can't really remove the annotation. The annotation in question is:

// GOOD [FALSE POSITIVE]: `call_use(buffer2, 2)` won't reach this point.

and this PR manages to remove the FP when the call originates from this source:

unsigned char buffer2[2];
call_use(buffer2,2);

but not from this source:

unsigned char buffer2[2];
call_call_use(buffer2,2);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Oh, great, test confusion.

Co-authored-by: Jeroen Ketema <93738568+jketema@users.noreply.github.com>
@MathiasVP MathiasVP merged commit 42356a8 into github:main Jun 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C++ no-change-note-required This PR does not need a change note

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants