C++: Allow annotating IR dumps with Alias Analysis info

This commit adds a `PrintAliasAnalysis.qll` module, which can be imported alongside `PrintIR.qll` to annotate those dumps with alias analysis results.
This commit is contained in:
Dave Bartolomeo
2021-05-07 16:02:54 -04:00
parent 3b04bedee0
commit 54b9f2175d
6 changed files with 171 additions and 0 deletions

View File

@@ -249,6 +249,10 @@
"cpp/ql/src/semmle/code/cpp/ir/implementation/aliased_ssa/internal/AliasAnalysis.qll",
"csharp/ql/src/experimental/ir/implementation/unaliased_ssa/internal/AliasAnalysis.qll"
],
"SSA PrintAliasAnalysis": [
"cpp/ql/src/semmle/code/cpp/ir/implementation/unaliased_ssa/internal/PrintAliasAnalysis.qll",
"cpp/ql/src/semmle/code/cpp/ir/implementation/aliased_ssa/internal/PrintAliasAnalysis.qll"
],
"C++ SSA AliasAnalysisImports": [
"cpp/ql/src/semmle/code/cpp/ir/implementation/unaliased_ssa/internal/AliasAnalysisImports.qll",
"cpp/ql/src/semmle/code/cpp/ir/implementation/aliased_ssa/internal/AliasAnalysisImports.qll"

View File

@@ -400,3 +400,46 @@ predicate addressOperandAllocationAndOffset(
)
)
}
/**
* Predicates used only for printing annotated IR dumps. These should not be used in production
* queries.
*/
module Print {
string getOperandProperty(Operand operand, string key) {
key = "alloc" and
result =
strictconcat(Configuration::Allocation allocation, IntValue bitOffset |
addressOperandAllocationAndOffset(operand, allocation, bitOffset)
|
allocation.toString() + Ints::getBitOffsetString(bitOffset), ", "
)
or
key = "prop" and
result =
strictconcat(Instruction destInstr, IntValue bitOffset, string value |
operandIsPropagatedIncludingByCall(operand, bitOffset, destInstr) and
if destInstr = operand.getUse()
then value = "@" + Ints::getBitOffsetString(bitOffset) + "->result"
else value = "@" + Ints::getBitOffsetString(bitOffset) + "->" + destInstr.getResultId()
|
value, ", "
)
}
string getInstructionProperty(Instruction instr, string key) {
key = "prop" and
result =
strictconcat(IntValue bitOffset, Operand sourceOperand, string value |
operandIsPropagatedIncludingByCall(sourceOperand, bitOffset, instr) and
if instr = sourceOperand.getUse()
then value = sourceOperand.getDumpId() + Ints::getBitOffsetString(bitOffset) + "->@"
else
value =
sourceOperand.getUse().getResultId() + "." + sourceOperand.getDumpId() +
Ints::getBitOffsetString(bitOffset) + "->@"
|
value, ", "
)
}
}

View File

@@ -0,0 +1,19 @@
/**
* Include this module to annotate IR dumps with information computed by `AliasAnalysis.qll`.
*/
private import AliasAnalysisInternal
private import InputIR
private import AliasAnalysisImports
private import AliasAnalysis
private import semmle.code.cpp.ir.internal.IntegerConstant
private class AliasPropertyProvider extends IRPropertyProvider {
override string getOperandProperty(Operand operand, string key) {
result = Print::getOperandProperty(operand, key)
}
override string getInstructionProperty(Instruction instr, string key) {
result = Print::getInstructionProperty(instr, key)
}
}

View File

@@ -400,3 +400,46 @@ predicate addressOperandAllocationAndOffset(
)
)
}
/**
* Predicates used only for printing annotated IR dumps. These should not be used in production
* queries.
*/
module Print {
string getOperandProperty(Operand operand, string key) {
key = "alloc" and
result =
strictconcat(Configuration::Allocation allocation, IntValue bitOffset |
addressOperandAllocationAndOffset(operand, allocation, bitOffset)
|
allocation.toString() + Ints::getBitOffsetString(bitOffset), ", "
)
or
key = "prop" and
result =
strictconcat(Instruction destInstr, IntValue bitOffset, string value |
operandIsPropagatedIncludingByCall(operand, bitOffset, destInstr) and
if destInstr = operand.getUse()
then value = "@" + Ints::getBitOffsetString(bitOffset) + "->result"
else value = "@" + Ints::getBitOffsetString(bitOffset) + "->" + destInstr.getResultId()
|
value, ", "
)
}
string getInstructionProperty(Instruction instr, string key) {
key = "prop" and
result =
strictconcat(IntValue bitOffset, Operand sourceOperand, string value |
operandIsPropagatedIncludingByCall(sourceOperand, bitOffset, instr) and
if instr = sourceOperand.getUse()
then value = sourceOperand.getDumpId() + Ints::getBitOffsetString(bitOffset) + "->@"
else
value =
sourceOperand.getUse().getResultId() + "." + sourceOperand.getDumpId() +
Ints::getBitOffsetString(bitOffset) + "->@"
|
value, ", "
)
}
}

View File

@@ -0,0 +1,19 @@
/**
* Include this module to annotate IR dumps with information computed by `AliasAnalysis.qll`.
*/
private import AliasAnalysisInternal
private import InputIR
private import AliasAnalysisImports
private import AliasAnalysis
private import semmle.code.cpp.ir.internal.IntegerConstant
private class AliasPropertyProvider extends IRPropertyProvider {
override string getOperandProperty(Operand operand, string key) {
result = Print::getOperandProperty(operand, key)
}
override string getInstructionProperty(Instruction instr, string key) {
result = Print::getInstructionProperty(instr, key)
}
}

View File

@@ -400,3 +400,46 @@ predicate addressOperandAllocationAndOffset(
)
)
}
/**
* Predicates used only for printing annotated IR dumps. These should not be used in production
* queries.
*/
module Print {
string getOperandProperty(Operand operand, string key) {
key = "alloc" and
result =
strictconcat(Configuration::Allocation allocation, IntValue bitOffset |
addressOperandAllocationAndOffset(operand, allocation, bitOffset)
|
allocation.toString() + Ints::getBitOffsetString(bitOffset), ", "
)
or
key = "prop" and
result =
strictconcat(Instruction destInstr, IntValue bitOffset, string value |
operandIsPropagatedIncludingByCall(operand, bitOffset, destInstr) and
if destInstr = operand.getUse()
then value = "@" + Ints::getBitOffsetString(bitOffset) + "->result"
else value = "@" + Ints::getBitOffsetString(bitOffset) + "->" + destInstr.getResultId()
|
value, ", "
)
}
string getInstructionProperty(Instruction instr, string key) {
key = "prop" and
result =
strictconcat(IntValue bitOffset, Operand sourceOperand, string value |
operandIsPropagatedIncludingByCall(sourceOperand, bitOffset, instr) and
if instr = sourceOperand.getUse()
then value = sourceOperand.getDumpId() + Ints::getBitOffsetString(bitOffset) + "->@"
else
value =
sourceOperand.getUse().getResultId() + "." + sourceOperand.getDumpId() +
Ints::getBitOffsetString(bitOffset) + "->@"
|
value, ", "
)
}
}