Skip to content

C++: Improve alias analysis for indirections #1736

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

Draft
wants to merge 13 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
Commits
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
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
import semmle.code.cpp.ir.implementation.unaliased_ssa.IR as InputIR
import AliasConfiguration as Configuration
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
private import cpp
private import semmle.code.cpp.ir.implementation.unaliased_ssa.IR
private import semmle.code.cpp.ir.implementation.unaliased_ssa.gvn.ValueNumbering
private import AliasAnalysis

/**
* A memory allocation that can be tracked by the AliasedSSA alias analysis.
* For now, we track all variables accessed within the function, including both local variables
* and global variables. In the future, we will track indirect parameters as well.
Copy link
Contributor

Choose a reason for hiding this comment

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

What about modeled allocators or default new?

*/
class Allocation extends ValueNumber {
IRVariable var;

Allocation() {
// For now, we only track variables.
var = this.getAnInstruction().(VariableAddressInstruction).getVariable()
}

final string getAllocationString() {
exists(string suffix |
result = var.toString() + suffix and
if isUnaliased() then
suffix = ""
else
suffix = "*"
)
}

final Type getType() {
result = var.getType()
}

final int getBitSize() {
result = getType().getSize() * 8
}

final predicate alwaysEscapes() {
// An automatic variable only escapes if its address is taken and escapes, but we assume that
// any other kind of variable always escapes.
not var instanceof IRAutomaticVariable
}

final predicate isUnaliased() {
not allocationEscapes(this)
}

final Instruction getABaseInstruction() {
// Any instruction with this value number serves as a base address for this allocation.
result = getAnInstruction()
}
}
Loading
Oops, something went wrong.