-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
C++: Add a new MemoryLocation
to represent sets of Allocation
s
#16907
Conversation
…d, we simply add flow through them.
…d 'hasOperandMemoryAccess' and add a boolean column indicating whether they relate to multiple 'Allocation's.
cpp/ql/lib/semmle/code/cpp/ir/implementation/unaliased_ssa/internal/SimpleSSA.qll
Dismissed
Show dismissed
Hide dismissed
…d memory location is that grouped memory location (or all aliased memory if it escapes).
…and 'getResultMemoryLocation'.
…ause of 'defBlock.getInstruction(oldOffset)' has a result.
…A so that the pyrameterized files compile.
… variable group's virtual variable is all aliased memory.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for going over this with us in Zoom. I've added a few more comments here.
cpp/ql/lib/semmle/code/cpp/ir/implementation/aliased_ssa/internal/SSAConstruction.qll
Show resolved
Hide resolved
cpp/ql/lib/semmle/code/cpp/ir/implementation/aliased_ssa/internal/SSAConstruction.qll
Outdated
Show resolved
Hide resolved
cpp/ql/lib/semmle/code/cpp/ir/implementation/aliased_ssa/internal/SSAConstruction.qll
Outdated
Show resolved
Hide resolved
cpp/ql/lib/semmle/code/cpp/ir/implementation/aliased_ssa/internal/SSAConstruction.qll
Show resolved
Hide resolved
or | ||
not isFirstInstructionBeforeUninitializedGroup(instruction, _) and | ||
result = getInstructionSuccessorAfterUninitializedGroup0(instruction, kind) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The instruction ordering code has accumulated a very high level of complexity for what it is, and I feel this is error prone (and difficult to maintain). I think we should discuss ways we can improve this in future, in particular the simple operation of appending one variable length block of instructions to another creates quite a lot of code / complexity at the moment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it would be good if we could do something prettier here in the future. It's doable for now since we're only injecting new UninitializedGroup
instructions and ChiInstruction
s (and because we know exactly the structure of these), but I agree that this could get unmanageable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would actually say it's already unmanageable, at least to my tolerance. I'm not suggesting we fix it here, I'll create an issue for discussion...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll get started on figuring out a more sensible way to structure this as a follow-up PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(I didn't actually create the issue, but we discussed stuff on another channel)
cpp/ql/lib/semmle/code/cpp/ir/implementation/aliased_ssa/internal/SSAConstruction.qll
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm happy with the changes, I'd like to know your thoughts about the DCA run:
- 16 lost results for
cpp/uninitialized-local
. - possible 5% analysis slowdown.
- changes in CPP IR inconsistencies, e.g. new
missingPhiOperand
inconsistencies.
|
I'm assuming @geoffw0 will be the one that approves the PR once happy. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm happy with this PR and the changes / new explanatory comment. 👍
Perhaps we should discuss analysis performance at one of the upcoming meetings, there have been a number of small regressions and improvements lately.
C++: Alias analysis follow-up to #16907
The what
This PR is an alternative to #16465 that:
cpp/uninitialized-local
query, andThe problem, as Dave explained very well in #16465, can be seen in this example:
The question is: what is the possible values of
x
once we reachuse(x)
? The current (incorrect) alias analysis onmain
reports that the only possible value ofx
isUninitialized
- which is certainly wrong! The value may be uninitialized, but it may also be5
.The how
In #16465 this was fixed by removing alias analysis support for
Phi
instructions. This meant that we would conflate any value that flows into aPhi
instruction with all aliased memory which effectively means that we wouldn't be able to say anything about the memory. This was making some of our tests unhappy in #16465.Instead of removing alias analysis support for
Phi
instructions, this PR adds a newMemoryLocation
that represents a set ofAllocation
s. That is, instead of saying that*p = 5
writes to all aliased memory we now have a memory location that represents a set of possible allocations. In the above case, that set of{x, y}
.Reviewing this PR
This PR is modifying code that we haven't touched in years so I've tried my best to split the changes into commits that can be reviewed independently.
I'm keeping this PR in draft for now as it depends on a yet-to-be-released feature of QL (i.e., the
QlBuiltins::InternSets
module. See 75c5d8f). Once 2.18.0 is out we can safely merge this PR ontomain
.Analyzing the results
On
samate
there are some new inconsistencies arising from themissingPhiOperand
check. In the first commit I've added a testcase that represents what's going on:on
main
the value of*data
has been merged into all aliased memory.However, after this PR we track the flow from
&intBuffer
and intodata
, and into the phi instruction at the merge point. However, because we don't know what memorydata
points to initially there is only one phi input at the merge point.I plan on fixing this unsoundness as a follow-up PR since I think this PR is large enough as-is. (I already have something for this locally.)